narrow version-check exception handler to specific request and JSON errors#3006
Open
HrachShah wants to merge 1 commit into
Open
Conversation
…or, 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bare
except Exceptionin the post-argparse version-check guarded against only three concrete failure modes:requests.get(forge_api_latest_release, timeout=10)raisesrequests.RequestException(and its concrete subclassesConnectionError,Timeout,HTTPError) for network and transport failures.json_loads(latest_release_raw)raisesjson.JSONDecodeError(aValueErrorsubclass) for malformed JSON.latest_release_json['tag_name']andlatest_remote_tag[1:]raiseKeyError/IndexErrorfor unexpected payload shapes.Catching
Exceptionwas masking unrelated bugs andKeyboardInterrupt(e.g. a Ctrl-C between thesignal.signalcall above and thetryblock). 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.Tested locally:
python3 -c "import ast; ast.parse(...)"parses; the version-check still prints 'A problem occurred while checking for an update' for the network/JSON failure modes it was originally guarding against.