fix: wrap float() in timeout_check with try/except for clean argparse error#2955
Open
imxde-code wants to merge 1 commit into
Open
fix: wrap float() in timeout_check with try/except for clean argparse error#2955imxde-code wants to merge 1 commit into
imxde-code wants to merge 1 commit into
Conversation
… error Passing a non-numeric value to --timeout (e.g. 'abc') previously caused a raw ValueError from float() to bubble up before argparse could handle it, resulting in an ugly unformatted traceback instead of the standard 'argument --timeout: invalid' error message. Wrapping the conversion in a try/except ValueError and re-raising as ArgumentTypeError lets argparse format and surface the error correctly, consistent with the existing behaviour for zero/negative values. Also adds regression tests for both non-numeric and non-positive inputs. Fixes sherlock-project#2866
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.
Summary
Fixes #2866
Passing a non-numeric value to
--timeout(e.g.sherlock --timeout abc user) currently raises a rawValueErrorfromfloat(value)before argparse can intercept it, producing an ugly unformatted traceback.Root cause
Fix
Argparse then formats this consistently as:
Tests added
Two parametrized regression tests in
test_ux.py:test_invalid_timeout_raises_argparse_error— covers non-numeric strings (abc,xyz,1.2.3,None)test_non_positive_timeout_raises_argparse_error— covers zero and negative values (pre-existing bug, now also tested)Test plan
sherlock --timeout abc user→ clean argparse error messagesherlock --timeout -1 user→ clean argparse error messagesherlock --timeout 5 user→ works normally