-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[Core] Display allowed values in error message when enum validation fails #17621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -497,8 +497,8 @@ def _check_value(self, action, value): # pylint: disable=too-many-statements, t | |
| else: | ||
| # `command_source` indicates command values have been parsed, value is an argument | ||
| parameter = action.option_strings[0] if action.option_strings else action.dest | ||
| error_msg = "{prog}: '{value}' is not a valid value for '{param}'.".format( | ||
| prog=self.prog, value=value, param=parameter) | ||
| error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choice}.".format( | ||
| prog=self.prog, value=value, param=parameter, choice=', '.join(sorted([str(x) for x in action.choices]))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order in error message is better to be consistent with the order in help info
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally prefer to keep the order because some choices may be more frequently used. |
||
| candidates = difflib.get_close_matches(value, action.choices, cutoff=0.7) | ||
| az_error = InvalidArgumentValueError(error_msg) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.