Skip to content

fix: catch ValueError instead of bare except in account CLI commands - #40356

Open
chelsealong wants to merge 2 commits into
langgenius:mainfrom
chelsealong:fix/account-cli-bare-except
Open

fix: catch ValueError instead of bare except in account CLI commands#40356
chelsealong wants to merge 2 commits into
langgenius:mainfrom
chelsealong:fix/account-cli-bare-except

Conversation

@chelsealong

Copy link
Copy Markdown
Contributor

Summary

reset-password and reset-email in api/commands/account.py wrap valid_password/email_validate in a bare except: block. Both validators only ever raise ValueError on invalid input, so the bare except unnecessarily catches everything else too, including KeyboardInterrupt and SystemExit. That makes the interactive CLI prompt unresponsive to Ctrl+C while it's waiting on these calls, since the interrupt gets swallowed and reported as an "Invalid password"/"Invalid email" message instead of stopping the command.

This narrows both except: clauses to except ValueError:, matching the exception the validators actually raise.

Fixes #40348

Test plan

Added api/tests/unit_tests/commands/test_account_commands.py with a regression test for each command. Each test mocks the validator to raise KeyboardInterrupt and asserts it propagates out of the command instead of being swallowed into an "Invalid password"/"Invalid email" message.

Confirmed the tests fail against the pre-fix code (bare except:) and pass with the fix:

$ uv run --project api pytest --timeout 30 api/tests/unit_tests/commands/test_account_commands.py -v --no-cov
api/tests/unit_tests/commands/test_account_commands.py::test_reset_password_does_not_swallow_keyboard_interrupt PASSED
api/tests/unit_tests/commands/test_account_commands.py::test_reset_email_does_not_swallow_keyboard_interrupt PASSED
2 passed, 1 warning in 1.20s

Also ran the full api/tests/unit_tests/commands/ suite (174 tests) to confirm no regressions, and ruff format --diff / ruff check on the changed files (both clean).

From Claude

reset-password and reset-email swallow all exceptions from
valid_password/email_validate, including KeyboardInterrupt and
SystemExit, making Ctrl+C unresponsive during the interactive CLI
prompt. Both validators only ever raise ValueError, so narrow the
except clause to that.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. refactor labels Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 58.26% 58.27% +0.00%
Strict coverage 57.84% 57.84% +0.00%
Typed symbols 38,287 38,291 +4
Untyped symbols 27,627 27,627 0
Modules 3144 3145 +1

Fixes pyrefly failures in the Style Check CI job (unannotated-return
and implicit-any-parameter on monkeypatch).
@chelsealong

Copy link
Copy Markdown
Contributor Author

Fixed the Style Check failure: added return and monkeypatch: pytest.MonkeyPatch type annotations to the two new regression tests, which pyrefly's unit-tests config was flagging (unannotated-return, implicit-any-parameter). Verified locally: ./dev/pyrefly-check-local now passes clean, mypy core check passes, the 174-test api/tests/unit_tests/commands/ suite still passes, and ruff format/ruff check are clean on the changed files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signal-Blocking Bare Except in Account CLI Tool

1 participant