From 1b1eb26fca521ad139b6d76dc9e9602b68059335 Mon Sep 17 00:00:00 2001 From: berettavexee Date: Sun, 14 Jun 2026 23:14:03 +0200 Subject: [PATCH] fix(cli): handle network errors in version check gracefully 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 --- streamrip/rip/cli.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/streamrip/rip/cli.py b/streamrip/rip/cli.py index 2b3f532e..f6e3b33a 100644 --- a/streamrip/rip/cli.py +++ b/streamrip/rip/cli.py @@ -457,24 +457,27 @@ async def latest_streamrip_version(verify_ssl: bool = True) -> tuple[str, str | Returns: A tuple of (version, release_notes) """ - # Create connector with appropriate SSL settings - connector_kwargs = get_aiohttp_connector_kwargs(verify_ssl=verify_ssl) - connector = aiohttp.TCPConnector(**connector_kwargs) - - async with aiohttp.ClientSession(connector=connector) as s: - async with s.get("https://pypi.org/pypi/streamrip/json") as resp: - data = await resp.json() - version = data["info"]["version"] - - if version == __version__: - return version, None - - async with s.get( - "https://api.github.com/repos/nathom/streamrip/releases/latest" - ) as resp: - json = await resp.json() - notes = json["body"] - return version, notes + try: + connector_kwargs = get_aiohttp_connector_kwargs(verify_ssl=verify_ssl) + connector = aiohttp.TCPConnector(**connector_kwargs) + + async with aiohttp.ClientSession(connector=connector) as s: + async with s.get("https://pypi.org/pypi/streamrip/json") as resp: + data = await resp.json(content_type=None) + version = data["info"]["version"] + + if version == __version__: + return version, None + + async with s.get( + "https://api.github.com/repos/nathom/streamrip/releases/latest" + ) as resp: + gh = await resp.json(content_type=None) + notes = gh.get("body") if isinstance(gh, dict) else None + return version, notes + except Exception as e: + logger.debug("Could not check for updates: %s", e) + return __version__, None if __name__ == "__main__":