fix(installer): handle TypeError and AttributeError during tree cache / tree.json retrieval#165
Conversation
… / tree.json retrieval
|
@MatrixNeoKozak is attempting to deploy a commit to the Max Ritter Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe ChangesMalformed tree.json fallback
Estimated code review effort: 1 (Trivial) | ~5 minutes Related PRs: None identified. Suggested labels: bug, tests Suggested reviewers: None identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
installer/downloads.py (2)
320-322: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSame observability gap on the API-fetch fallback.
Same concern as the tree.json path above: broadened exception handling silently returns
[]with no logging, making it hard to diagnose why the installer fell back to "no files" in the field.♻️ Suggested addition of debug logging
except (urllib.error.URLError, json.JSONDecodeError, TypeError, AttributeError, TimeoutError): + logger.debug("GitHub API tree fetch/parse failed", exc_info=True) return []As per path instructions, installer code should have "Proper error handling and user feedback."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@installer/downloads.py` around lines 320 - 322, The API-fetch fallback in the installer currently swallows exceptions and returns an empty list without any visibility. In the fallback handler around the download/API retrieval logic in installer/downloads.py, add debug or warning logging that captures the exception details before returning [] so failures are diagnosable in the field. Keep the existing fallback behavior, but ensure the logging happens in the exception path that handles urllib.error.URLError, json.JSONDecodeError, TypeError, AttributeError, and TimeoutError.Source: Path instructions
268-283: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winConsider logging on fallback for observability.
Extending the except clause to cover
TypeError/AttributeErrorcorrectly handles malformedtree.jsonpayloads (e.g.,"tree" in dataon a non-dict). However, the try block also wraps network I/O, and any unrelatedTypeError/AttributeErrorbug here would be silently swallowed indistinguishably from a legitimate malformed-payload case, with no diagnostic trail.♻️ Suggested addition of debug logging
except (urllib.error.HTTPError, urllib.error.URLError, json.JSONDecodeError, TypeError, AttributeError, TimeoutError): - pass + logger.debug("tree.json fetch/parse failed, falling back to API", exc_info=True)As per path instructions, installer code should have "Proper error handling and user feedback."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@installer/downloads.py` around lines 268 - 283, The tree JSON fetch fallback is silently swallowing both malformed-payload errors and unrelated network/runtime failures, which removes any diagnostic trail. In the helper that calls urllib.request.urlopen for tree_json_url and builds remote_files, keep the broader exception handling but add debug logging in the except path with the URL and exception details before returning the fallback result. Make sure the log clearly distinguishes an invalid payload from an unexpected TypeError/AttributeError so observability is preserved while still handling the failure safely.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@installer/downloads.py`:
- Around line 320-322: The API-fetch fallback in the installer currently
swallows exceptions and returns an empty list without any visibility. In the
fallback handler around the download/API retrieval logic in
installer/downloads.py, add debug or warning logging that captures the exception
details before returning [] so failures are diagnosable in the field. Keep the
existing fallback behavior, but ensure the logging happens in the exception path
that handles urllib.error.URLError, json.JSONDecodeError, TypeError,
AttributeError, and TimeoutError.
- Around line 268-283: The tree JSON fetch fallback is silently swallowing both
malformed-payload errors and unrelated network/runtime failures, which removes
any diagnostic trail. In the helper that calls urllib.request.urlopen for
tree_json_url and builds remote_files, keep the broader exception handling but
add debug logging in the except path with the URL and exception details before
returning the fallback result. Make sure the log clearly distinguishes an
invalid payload from an unexpected TypeError/AttributeError so observability is
preserved while still handling the failure safely.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2215eeac-26be-40b8-a14b-9283bb1de695
📒 Files selected for processing (2)
installer/downloads.pyinstaller/tests/unit/test_downloads.py
|
@MatrixNeoKozak Thanks for your contribution! This has been included as part of 9.10.1 :) |
Catches TypeError and AttributeError during tree JSON parsing in get_repo_files fallback mechanisms. This ensures that the installer falls back to alternative methods or returns cleanly if GitHub releases return non-dictionary payloads or malformed JSON structures, instead of raising unhandled exceptions and crashing the installer.
Summary by cubic
Prevent installer crashes when
tree.jsonor tree cache responses are malformed by catchingTypeErrorandAttributeError, and falling back to the API or returning safely. Adds a unit test to cover the malformedtree.jsoncase.TypeErrorandAttributeErrorininstaller.downloads.get_repo_filesfor both tree cache andtree.jsonparsing paths.tree.jsonreturns an invalid structure.Written for commit a070439. Summary will update on new commits.
Summary by CodeRabbit