fix: catch ValueError instead of bare except in account CLI commands - #40356
Open
chelsealong wants to merge 2 commits into
Open
fix: catch ValueError instead of bare except in account CLI commands#40356chelsealong wants to merge 2 commits into
chelsealong wants to merge 2 commits into
Conversation
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.
Contributor
Pyrefly Type Coverage
|
Fixes pyrefly failures in the Style Check CI job (unannotated-return and implicit-any-parameter on monkeypatch).
Contributor
Author
|
Fixed the Style Check failure: added return and |
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
reset-passwordandreset-emailinapi/commands/account.pywrapvalid_password/email_validatein a bareexcept:block. Both validators only ever raiseValueErroron invalid input, so the bare except unnecessarily catches everything else too, includingKeyboardInterruptandSystemExit. 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 toexcept ValueError:, matching the exception the validators actually raise.Fixes #40348
Test plan
Added
api/tests/unit_tests/commands/test_account_commands.pywith a regression test for each command. Each test mocks the validator to raiseKeyboardInterruptand 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:Also ran the full
api/tests/unit_tests/commands/suite (174 tests) to confirm no regressions, andruff format --diff/ruff checkon the changed files (both clean).From Claude