From 1f8e575d3aa8217b5b59e9f3f684e43aff0d35a8 Mon Sep 17 00:00:00 2001 From: Zo Bot Date: Mon, 15 Jun 2026 11:33:58 +0000 Subject: [PATCH] narrow version-check exception handler to (RequestException, ValueError, KeyError) The bare `except Exception` in the post-argparse version-check only guarded against three concrete failure modes: - requests.get(forge_api_latest_release, timeout=10) raises requests.RequestException (and its concrete subclasses ConnectionError, Timeout, HTTPError) for network and transport failures. - json_loads(latest_release_raw) raises json.JSONDecodeError (a ValueError subclass) for malformed JSON, and int() conversion of tag_name substrings raises ValueError on bad digits. - latest_release_json['tag_name'] and latest_remote_tag[1:] raise KeyError / IndexError for unexpected payload shapes. Catching Exception was masking unrelated bugs (a typo in forge_api_latest_release, an unhandled unicode issue in latest_release_raw, a broken Response.json shortcut) and turning them into a confusing 'A problem occurred while checking for an update' line on stderr, and KeyboardInterrupt / SystemExit raised during a Ctrl-C just after the signal handler install (between the signal.signal line above and the try/except block) would also be swallowed here, leaving the user with a half-shut-down process. The narrower tuple keeps the original 'silently report the version-check failure' behaviour for the three real failure modes and lets other exceptions propagate with their full traceback. --- sherlock_project/sherlock.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sherlock_project/sherlock.py b/sherlock_project/sherlock.py index a284f47ad5..dea3b353e6 100644 --- a/sherlock_project/sherlock.py +++ b/sherlock_project/sherlock.py @@ -708,7 +708,17 @@ def main(): f"\n{latest_release_json['html_url']}" ) - except Exception as error: + except (requests.RequestException, ValueError, KeyError) as error: + # requests.get() raises requests.RequestException (and its concrete + # subclasses ConnectionError, Timeout, HTTPError) for network and + # transport failures; json_loads() raises json.JSONDecodeError (a + # ValueError subclass) for malformed JSON; and the ["tag_name"] / + # latest_remote_tag[1:] lookups raise KeyError / IndexError for + # unexpected payload shapes. Catching the bare Exception was + # masking KeyboardInterrupt during a Ctrl-C just after the version + # check and turning any unrelated bug (a typo in forge_api_latest_release, + # an unhandled unicode issue in latest_release_raw) into a confusing + # 'A problem occurred while checking for an update' line on stderr. print(f"A problem occurred while checking for an update: {error}") # Make prompts