]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 11 Jun 2023 15:42:06 +0000 (17:42 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 11 Jun 2023 15:42:06 +0000 (17:42 +0200)
- always transport causing exception
- some places may still handle it

fba/commands.py
fba/federation.py
fba/instances.py
fba/network.py

index f84ce6f6d2a02eaa4fe0dbe40dc70c7efc7f162d..d71c0ae7a4908e53f67d53b46a07d66ae5156002 100644 (file)
@@ -440,7 +440,7 @@ def fetch_fbabot_atom(args: argparse.Namespace):
 
     # DEBUG: print("DEBUG: EXIT!")
 
-def fetch_instances(args: argparse.Namespace):
+def fetch_instances(args: argparse.Namespace) -> int:
     # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
     locking.acquire()
 
@@ -451,11 +451,11 @@ def fetch_instances(args: argparse.Namespace):
     except network.exceptions as exception:
         print(f"WARNING: Exception '{type(exception)}' during fetching instances from args.domain='{args.domain}'")
         instances.update_last_error(args.domain, exception)
-        return
+        return 100
 
     if args.single:
         # DEBUG: print("DEBUG: Not fetching more instances - EXIT!")
-        return
+        return 0
 
     # Loop through some instances
     fba.cursor.execute(
@@ -478,6 +478,7 @@ def fetch_instances(args: argparse.Namespace):
             instances.update_last_error(row[0], exception)
 
     # DEBUG: print("DEBUG: EXIT!")
+    return 0
 
 def fetch_federater(args: argparse.Namespace):
     # DEBUG: print(f"DEBUG: args[]='{type(args)}' - CALLED!")
index ee839c78ca17bd0212161fb932fc28e58f388d74..1e400529b6521b099cc1eb4ada8ebc87e98731b4 100644 (file)
@@ -200,7 +200,11 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict:
         headers = csrf.determine(domain, dict())
     except network.exceptions as exception:
         print(f"WARNING: Exception '{type(exception)}' during checking CSRF (nodeinfo,{__name__}) - EXIT!")
-        return dict()
+        return {
+            "status_code"  : 500,
+            "error_message": f"exception[{type(exception)}]='{str(exception)}'",
+            "exception"    : exception,
+        }
 
     request_paths = [
        "/nodeinfo/2.1.json",
@@ -254,7 +258,8 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict:
         print(f"WARNING: Exception '{type(exception)}' during checking CSRF (fetch_wellknown,{__name__}) - EXIT!")
         return {
             "status_code"  : 500,
-            "error_message": type(exception)
+            "error_message": type(exception),
+            "exception"    : exception,
         }
 
     # DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain)
@@ -375,8 +380,11 @@ def determine_software(domain: str, path: str = None) -> str:
 
     # DEBUG: print(f"DEBUG: data[{type(data)}]='{data}'")
     if "error_message" in data:
-        # DEBUG: print("DEBUG: Could not determine software type:", domain)
-        return fetch_generator_from_path(domain)
+        # DEBUG: print(f"DEBUG: Could not determine software type, domain='{domain}'")
+        if "exception" in data:
+            raise Exception(f"Cannot fetch nodeinfo from domain='{domain}': '{data['error_message']}'") from data["exception"]
+        else:
+            raise Exception(f"Cannot fetch nodeinfo from domain='{domain}': '{data['error_message']}'")
 
     # DEBUG: print("DEBUG: data():", len(data), data)
     if "status" in data["json"] and data["json"]["status"] == "error" and "message" in data["json"]:
index 039661d6cc767f386ee0052fe232e1e31f932de0..e2da016fcbb5a353e20817b882c84ebd0e0705b1 100644 (file)
@@ -206,33 +206,28 @@ def add(domain: str, origin: str, command: str, path: str = None):
             return
 
     print(f"INFO: Adding instance domain='{domain}' (origin='{origin}',software='{software}')")
-    try:
-        fba.cursor.execute(
-            "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
-            (
-               domain,
-               origin,
-               command,
-               fba.get_hash(domain),
-               software,
-               time.time()
-            ),
-        )
-
-        cache.set_sub_key("is_registered", domain, True)
-
-        if has_pending_instance_data(domain):
-            # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
-            set_data("last_status_code"  , domain, None)
-            set_data("last_error_details", domain, None)
-            update_data(domain)
-
-    except BaseException as exception:
-        update_last_error(domain, exception)
-        raise Exception(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") from exception
-    else:
-        # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
-        update_last_nodeinfo(domain)
+    fba.cursor.execute(
+        "INSERT INTO instances (domain, origin, command, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
+        (
+           domain,
+           origin,
+           command,
+           fba.get_hash(domain),
+           software,
+           time.time()
+        ),
+    )
+
+    cache.set_sub_key("is_registered", domain, True)
+
+    if has_pending_instance_data(domain):
+        # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
+        set_data("last_status_code"  , domain, None)
+        set_data("last_error_details", domain, None)
+        update_data(domain)
+
+    # DEBUG: print(f"DEBUG: Updating nodeinfo for domain='{domain}'")
+    update_last_nodeinfo(domain)
 
     # DEBUG: print("DEBUG: EXIT!")
 
@@ -301,14 +296,10 @@ def is_registered(domain: str) -> bool:
     # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
     if not cache.key_exists("is_registered"):
         # DEBUG: print("DEBUG: Cache for 'is_registered' not initialized, fetching all rows ...")
-        try:
-            fba.cursor.execute("SELECT domain FROM instances")
-
-            # Check Set all
-            cache.set_all("is_registered", fba.cursor.fetchall(), True)
-        except BaseException as exception:
-            update_last_error(domain, exception)
-            raise Exception(f"ERROR: failed SQL query: domain='{domain}',exception[{type(exception)}]:'{str(exception)}'") from exception
+        fba.cursor.execute("SELECT domain FROM instances")
+
+        # Check Set all
+        cache.set_all("is_registered", fba.cursor.fetchall(), True)
 
     # Is cache found?
     registered = cache.sub_key_exists("is_registered", domain)
index 281afb2f66f90bbf3eb83a58617f167650e92a11..bc7a95f2201ce9ca829a98ead234f4f265462bea 100644 (file)
@@ -82,6 +82,7 @@ def post_json_api(domain: str, path: str, data: str, headers: dict = {}) -> dict
         # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
         json_reply["status_code"]   = 999
         json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+        json_reply["exception"]     = exception
         instances.update_last_error(domain, exception)
         raise exception
 
@@ -115,6 +116,7 @@ def fetch_api_url(url: str, timeout: tuple) -> dict:
         # DEBUG: print(f"DEBUG: Fetching '{url}' failed. exception[{type(exception)}]='{str(exception)}'")
         json_reply["status_code"]   = 999
         json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+        json_reply["exception"]     = exception
         raise exception
 
     # DEBUG: print(f"DEBUG: Returning json_reply({len(json_reply)})=[]:{type(json_reply)}")
@@ -151,6 +153,7 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
         # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
         json_reply["status_code"]   = 999
         json_reply["error_message"] = f"exception['{type(exception)}']='{str(exception)}'"
+        json_reply["exception"]     = exception
         instances.update_last_error(domain, exception)
         raise exception