Skip to content

fix(cli): handle network errors in version check gracefully#995

Open
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/cli-version-check-network-errors
Open

fix(cli): handle network errors in version check gracefully#995
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/cli-version-check-network-errors

Conversation

@berettavexee

@berettavexee berettavexee commented Jun 14, 2026

Copy link
Copy Markdown

Problem

After a successful download, the CLI crashes with a traceback if the GitHub releases API returns a non-JSON response (504 gateway timeout, rate-limit HTML page, etc.):

ContentTypeError: 504, message='Attempt to decode JSON with unexpected mimetype:
text/html; charset=utf-8',
url='https://api.github.com/repos/nathom/streamrip/releases/latest'

Two root causes:

  1. aiohttp's resp.json() validates the Content-Type header and raises ContentTypeError on anything other than application/json.
  2. The exception propagates uncaught all the way to the top-level CLI handler, crashing the process even though the download itself completed successfully.

Fix

  • Pass content_type=None to both resp.json() calls to skip MIME type validation — the response is parsed as JSON regardless, and a JSONDecodeError is caught by the outer try/except below.
  • Use gh.get("body") instead of gh["body"] to handle error responses from the GitHub API (rate-limit, 404, etc.) that don't include a body field.
  • Wrap the entire function in try/except Exception so any network failure (timeout, DNS, SSL, parse error) is logged at DEBUG level and the check is silently skipped — the version check should never interrupt or crash a download session.

Test plan

  • Normal run with working network → update notice shown if newer version exists, nothing shown if up to date
  • GitHub API returns 504 → no crash, no notice
  • GitHub API rate-limited (returns JSON error object without body) → no crash, no notice
  • No network at all → no crash, no notice

🤖 Generated with Claude Code

The GitHub API can return non-JSON responses (504, rate limit HTML page)
causing ContentTypeError to crash the CLI after a successful download.

- Pass content_type=None to resp.json() to skip MIME type validation
- Use gh.get("body") instead of gh["body"] in case the response is an
  error object without that field
- Wrap the entire function in try/except so any network failure is
  silently logged at DEBUG level and the check is skipped cleanly

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant