fix: show custom error messages when hide_input=True#3321
Closed
MAXDVVV wants to merge 1 commit intopallets:mainfrom
Closed
fix: show custom error messages when hide_input=True#3321MAXDVVV wants to merge 1 commit intopallets:mainfrom
MAXDVVV wants to merge 1 commit intopallets:mainfrom
Conversation
Previously, when hide_input=True and a type's convert() raised a UsageError (e.g. BadParameter), the custom error message was replaced with a generic 'Error: The value you entered was invalid.' message. The hide_input flag should only affect whether the input value is echoed during typing, not whether custom validation error messages are displayed. Custom error messages from type validation are written by the developer and do not contain the secret input value. Fixes pallets#2809
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.
Problem
When using
hide_input=Truewith a custom type that raisesBadParameter(viaself.fail()), the custom error message is swallowed and replaced with a generic"Error: The value you entered was invalid.".This is because
termui.pyhas an explicit branch that replaces anyUsageErrormessage with a hardcoded string whenhide_input=True:Reproduction
Entering "short" shows:
Error: The value you entered was invalid.Expected:
Error: Password must be at least 8 charactersFix
Remove the
hide_inputbranch in theUsageErrorhandler — always show the actual error message. Thehide_inputflag should only affect whether the input value is echoed during typing, not whether the developer's custom validation error messages are displayed.Custom error messages are written by the developer and don't contain the secret input value, so there's no security reason to suppress them.
Test
Added
test_hide_input_shows_custom_error— verifies custom error messages from type validation are shown even whenhide_input=True.Fixes #2809