-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[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
Conversation
| 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]))) |
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.
Do we need sorted? Shall we respect the order in swagger definition?
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.
The order in error message is better to be consistent with the order in help info
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.
I personally prefer to keep the order because some choices may be more frequently used.
| 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( |
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.
| error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choice}.".format( | |
| error_msg = "{prog}: '{value}' is not a valid value for '{param}'. Allowed values: {choices}.".format( |
|
@jiasli for awareness. I remember we discussed this before, any plans for this feature in Knack? |
|
@xfz11 Can you help paste some creenshots in PR description about what the chanegs will look like before and after? The cases we need to consider include
|
|
The knack implementation is microsoft/knack#244 and have been released in v0.8.1. I have no strong opinion in CLI's behavior and will defer that to @houk-ms. |
|
@Juliehzl Do you have concerns about it if we decide to display all the possbile candidates? |
Description
When the enum validation fails, error message would show the allowed values to improve user experience


Before:
After:
The case in which the candiate list is shown along with the best match candidate:

Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change.
[Component Name 2] az command b: Add some customer-facing feature.
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.