Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sherlock_project/sherlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,12 @@ def timeout_check(value):
NOTE: Will raise an exception if the timeout in invalid.
"""

float_value = float(value)
try:
float_value = float(value)
except (TypeError, ValueError) as exc:
raise ArgumentTypeError(
f"Invalid timeout value: {value}. Timeout must be a positive number."
) from exc

if float_value <= 0:
raise ArgumentTypeError(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ux.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ def test_wildcard_username_expansion():
def test_no_usernames_provided(cliargs):
with pytest.raises(InteractivesSubprocessError, match=r"error: the following arguments are required: USERNAMES"):
Interactives.run_cli(cliargs)

@pytest.mark.parametrize('cliargs', [
'--timeout abc testuser',
'--timeout not-a-number testuser',
])
def test_invalid_timeout_reports_argparse_error(cliargs):
with pytest.raises(InteractivesSubprocessError, match=r"argument --timeout: Invalid timeout value"):
Interactives.run_cli(cliargs)