Skip to content

asl-node-auth-check: node changed to s in lookup#183

Merged
jxmx merged 2 commits into
developfrom
auth_check-error
Mar 27, 2026
Merged

asl-node-auth-check: node changed to s in lookup#183
jxmx merged 2 commits into
developfrom
auth_check-error

Conversation

@mkmer
Copy link
Copy Markdown
Contributor

@mkmer mkmer commented Mar 27, 2026

Robustify failures from get_node_regtime()

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved node registration information retrieval accuracy.
    • Fixed UDP port detection for proper node status verification.
    • Enhanced error handling and reporting for missing registration data.

Robustify failures in `get_node_regtime()`
@mkmer mkmer added the bug Something isn't working label Mar 27, 2026
@mkmer mkmer requested a review from jxmx March 27, 2026 14:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 27, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 440cf37c-1a08-4218-b1af-a8a7cf83b3e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auth_check-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
bin/asl-node-auth-check (1)

360-365: ⚠️ Potential issue | 🔴 Critical

Handle empty array responses from the API endpoint.

The new endpoint at https://www.allstarlink.org/nodelist/nodelist-server.php?s={node} can return an empty JSON array [], but the code at line 398 directly accesses node_reginfo[0] without checking if the list is empty. This will raise an IndexError when the API returns no registration data. Additionally, if 'regseconds' is missing from the response, .get('regseconds') will return None, causing a TypeError when passed to datetime.fromtimestamp() on line 399.

Add a check to ensure node_reginfo is not an empty list before accessing the first element, and handle the case where 'regseconds' is missing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/asl-node-auth-check` around lines 360 - 365, The API response handling
must guard against empty arrays and missing 'regseconds': after calling
response.json() (assign to node_reginfo), check if not node_reginfo or
len(node_reginfo) == 0 and return None (or otherwise abort processing) before
accessing node_reginfo[0]; then extract regseconds =
node_reginfo[0].get('regseconds') and verify it is a numeric value (int/float)
before passing it to datetime.fromtimestamp(); if regseconds is missing or not
numeric, handle by returning None or skipping timestamp conversion to avoid
TypeError.
🧹 Nitpick comments (2)
bin/asl-node-auth-check (2)

407-408: Similar KeyError risk on iptime access.

stats['node']['iptime'] can also raise KeyError if the field is missing. Consider wrapping with a try-except or using .get() with a default:

🛡️ Defensive access for iptime
-    iptime = stats['node']['iptime']
-    print_info(f"Last time IP changed was {iptime} UTC")
+    iptime = stats.get('node', {}).get('iptime')
+    if iptime:
+        print_info(f"Last time IP changed was {iptime} UTC")
+    else:
+        print_warning("IP change time not available in stats")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/asl-node-auth-check` around lines 407 - 408, Accessing
stats['node']['iptime'] can raise a KeyError; update the code that reads iptime
(the stats variable and the print_info call) to defensively fetch the value,
e.g. use stats.get('node', {}).get('iptime') with a sensible default or wrap in
try/except KeyError and handle missing iptime before calling print_info so you
don't crash when the field is absent.

382-391: Consider defensive access for nested dictionary keys.

The direct key access stats['node']['server']['udpport'] will raise a KeyError if the response structure differs from expected. Given the PR's goal to robustify failure handling, consider using defensive access:

🛡️ Proposed defensive access
-    
-    stats_udpport = stats['node']['server']['udpport']
+
+    try:
+        stats_udpport = stats['node']['server']['udpport']
+    except (KeyError, TypeError):
+        print_error("Stats response missing expected UDP port structure")
+        n_errors += 1
+        return n_errors, n_warnings
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/asl-node-auth-check` around lines 382 - 391, The code directly indexes
stats['node']['server']['udpport'] which can raise KeyError if the response
shape changes; update the access to be defensive (e.g., use nested .get calls or
try/except) when reading stats_udpport from stats, handle the missing-key case
by logging a clear error via print_error (or print_info) and incrementing
n_errors, and only perform the comparison against bind_udpport when
stats_udpport is present; reference the stats_udpport variable, the stats dict,
bind_udpport, print_error/print_ok, and n_errors when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bin/asl-node-auth-check`:
- Around line 394-399: The current code assumes node_reginfo contains an element
with a valid 'regseconds' value; update the block that computes reg_since and
reg_since_dt to first verify node_reginfo is a non-empty list and that
node_reginfo[0] contains a non-null numeric 'regseconds' before calling
datetime.fromtimestamp; if the list is empty or 'regseconds' is missing/None/not
a number, call print_error with a descriptive message, increment n_errors and
return n_errors, n_warnings (same as the existing null-case path). Reference the
existing variables and functions: node_reginfo, node_reginfo[0], reg_since,
reg_since_dt, datetime.fromtimestamp, UTC, print_error, n_errors, n_warnings.

---

Outside diff comments:
In `@bin/asl-node-auth-check`:
- Around line 360-365: The API response handling must guard against empty arrays
and missing 'regseconds': after calling response.json() (assign to
node_reginfo), check if not node_reginfo or len(node_reginfo) == 0 and return
None (or otherwise abort processing) before accessing node_reginfo[0]; then
extract regseconds = node_reginfo[0].get('regseconds') and verify it is a
numeric value (int/float) before passing it to datetime.fromtimestamp(); if
regseconds is missing or not numeric, handle by returning None or skipping
timestamp conversion to avoid TypeError.

---

Nitpick comments:
In `@bin/asl-node-auth-check`:
- Around line 407-408: Accessing stats['node']['iptime'] can raise a KeyError;
update the code that reads iptime (the stats variable and the print_info call)
to defensively fetch the value, e.g. use stats.get('node', {}).get('iptime')
with a sensible default or wrap in try/except KeyError and handle missing iptime
before calling print_info so you don't crash when the field is absent.
- Around line 382-391: The code directly indexes
stats['node']['server']['udpport'] which can raise KeyError if the response
shape changes; update the access to be defensive (e.g., use nested .get calls or
try/except) when reading stats_udpport from stats, handle the missing-key case
by logging a clear error via print_error (or print_info) and incrementing
n_errors, and only perform the comparison against bind_udpport when
stats_udpport is present; reference the stats_udpport variable, the stats dict,
bind_udpport, print_error/print_ok, and n_errors when making these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4ebde32-aa2b-4c45-8523-4d9985d19050

📥 Commits

Reviewing files that changed from the base of the PR and between 49da9ab and a12388e.

📒 Files selected for processing (1)
  • bin/asl-node-auth-check

Comment thread bin/asl-node-auth-check
Comment on lines +394 to 399
if node_reginfo is None:
print_error(f"No registration information available.")
n_errors += 1
return n_errors, n_warnings
reg_since = node_reginfo[0].get('regseconds')
reg_since_dt = datetime.fromtimestamp(reg_since, UTC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Incomplete robustness: handle empty list and missing regseconds.

The null check on line 394 is good, but two edge cases remain unhandled:

  1. Empty list: If the API returns [], node_reginfo[0] raises IndexError.
  2. Missing key: If regseconds is absent, .get() returns None, and datetime.fromtimestamp(None, UTC) raises TypeError.
🐛 Proposed fix for complete robustness
     node_reginfo = get_node_regtime(node)
-    if node_reginfo is None:
+    if node_reginfo is None or len(node_reginfo) == 0:
         print_error(f"No registration information available.")
         n_errors += 1
         return n_errors, n_warnings
-    reg_since = node_reginfo[0].get('regseconds')
+
+    reg_since = node_reginfo[0].get('regseconds')
+    if reg_since is None:
+        print_error("Registration info missing 'regseconds' field.")
+        n_errors += 1
+        return n_errors, n_warnings
+
     reg_since_dt = datetime.fromtimestamp(reg_since, UTC)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if node_reginfo is None:
print_error(f"No registration information available.")
n_errors += 1
return n_errors, n_warnings
reg_since = node_reginfo[0].get('regseconds')
reg_since_dt = datetime.fromtimestamp(reg_since, UTC)
if node_reginfo is None or len(node_reginfo) == 0:
print_error(f"No registration information available.")
n_errors += 1
return n_errors, n_warnings
reg_since = node_reginfo[0].get('regseconds')
if reg_since is None:
print_error("Registration info missing 'regseconds' field.")
n_errors += 1
return n_errors, n_warnings
reg_since_dt = datetime.fromtimestamp(reg_since, UTC)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/asl-node-auth-check` around lines 394 - 399, The current code assumes
node_reginfo contains an element with a valid 'regseconds' value; update the
block that computes reg_since and reg_since_dt to first verify node_reginfo is a
non-empty list and that node_reginfo[0] contains a non-null numeric 'regseconds'
before calling datetime.fromtimestamp; if the list is empty or 'regseconds' is
missing/None/not a number, call print_error with a descriptive message,
increment n_errors and return n_errors, n_warnings (same as the existing
null-case path). Reference the existing variables and functions: node_reginfo,
node_reginfo[0], reg_since, reg_since_dt, datetime.fromtimestamp, UTC,
print_error, n_errors, n_warnings.

@jxmx
Copy link
Copy Markdown
Member

jxmx commented Mar 27, 2026

Ugh, I forgot this was using ?node=. I added that back to the website. I also pushed two small fixes to this branch as well.

@jxmx jxmx merged commit ee80dc0 into develop Mar 27, 2026
4 checks passed
@jxmx jxmx deleted the auth_check-error branch March 27, 2026 15:59
@Allan-N Allan-N changed the title asl-node-auth-check: node changed to s in lookup. asl-node-auth-check: node changed to s in lookup Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants