Skip to content

fix(installer): handle TypeError and AttributeError during tree cache / tree.json retrieval#165

Closed
MatrixNeoKozak wants to merge 1 commit into
maxritter:mainfrom
MatrixNeoKozak:fix/improvement-1783436987975
Closed

fix(installer): handle TypeError and AttributeError during tree cache / tree.json retrieval#165
MatrixNeoKozak wants to merge 1 commit into
maxritter:mainfrom
MatrixNeoKozak:fix/improvement-1783436987975

Conversation

@MatrixNeoKozak

@MatrixNeoKozak MatrixNeoKozak commented Jul 7, 2026

Copy link
Copy Markdown

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.json or tree cache responses are malformed by catching TypeError and AttributeError, and falling back to the API or returning safely. Adds a unit test to cover the malformed tree.json case.

  • Bug Fixes
    • Catch TypeError and AttributeError in installer.downloads.get_repo_files for both tree cache and tree.json parsing paths.
    • Fallback to the GitHub API or return an empty list instead of raising unhandled exceptions.
    • Added a unit test to confirm fallback when tree.json returns an invalid structure.

Written for commit a070439. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved file discovery reliability when cached repository data is missing or malformed.
    • If repository tree data can’t be parsed or returned in an unexpected format, the app now safely falls back to the GitHub API or returns no files instead of failing.
    • Added test coverage for fallback behavior with malformed tree data.

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

@MatrixNeoKozak is attempting to deploy a commit to the Max Ritter Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The get_repo_files() function's exception handling is broadened to catch TypeError and AttributeError in both the initial tree.json fetch and the GitHub API trees fetch, returning an empty list on failure. A new unit test validates the fallback behavior when tree.json is malformed.

Changes

Malformed tree.json fallback

Layer / File(s) Summary
Expanded exception handling
installer/downloads.py
Both the initial tree.json retrieval and the later GitHub API trees fetch now also catch TypeError and AttributeError, returning [] on failure instead of propagating the exception.
Fallback validation test
installer/tests/unit/test_downloads.py
New unit test mocks malformed tree.json content to trigger a TypeError, confirms get_repo_files falls back to the GitHub API, asserts exactly two urlopen calls, and validates the returned file path and SHA.

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the installer fix and the newly handled TypeError/AttributeError cases in tree cache and tree.json retrieval.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
installer/downloads.py (2)

320-322: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Same 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 win

Consider logging on fallback for observability.

Extending the except clause to cover TypeError/AttributeError correctly handles malformed tree.json payloads (e.g., "tree" in data on a non-dict). However, the try block also wraps network I/O, and any unrelated TypeError/AttributeError bug 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

📥 Commits

Reviewing files that changed from the base of the PR and between 807881b and a070439.

📒 Files selected for processing (2)
  • installer/downloads.py
  • installer/tests/unit/test_downloads.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@maxritter

Copy link
Copy Markdown
Owner

@MatrixNeoKozak Thanks for your contribution! This has been included as part of 9.10.1 :)

@maxritter maxritter closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants