[Core] Display allowed values in error message when enum validation fails#17621
[Core] Display allowed values in error message when enum validation fails#17621
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.
Do we need sorted? Shall we respect the order in swagger definition?
There was a problem hiding this comment.
The order in error message is better to be consistent with the order in help info
There was a problem hiding this comment.
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.
| 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.