You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After looking at this a bit more closely, I'm not convinced the behavior is wrong.
The behavior you see when setting ArgumentResult.ErrorMessage hasn't actually changed. What changed is we removed the string return value from the validator delegate which now forces the use of ArgumentResult.ErrorMessage, meaning now there's only one way to display an error. This was intentional. What I didn't anticipate was that because the same ArgumentResult instance is passed in turn to each validator, they also share a single ErrorMessage rather than each getting to contribute their own error messages. This was not intentional.
Without changing the API, the old behavior can still be achieved: the second validator for example could append to the ErrorMessage that the previous one set. (I don't know if that's the right thing to do, but it's worth mentioning.)
Another approach would be to change the API, e.g. replace the ErrorMessage property with something like AddErrorMessage, or a List<string> ErrorMessages. I'm not sure how valuable this extra level of granularity would be.
Current behavior leads to the following output when using UseParseErrorReporting():
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Unrecognized command or argument(s): '--language','F#'.
Description:
Installs a template package.
Usage:
new3 install <package>... [options]
Arguments:
<package> NuGet package ID or path to folder or NuGet package to install.
To install the NuGet package of certain version, use <package ID>::<version>.
Options:
--interactive Allows the command to stop and wait for user input or action (for
example to complete authentication).
--add-source, --nuget-source <nuget-source> Specifies a NuGet source to use during install.
-?, -h, --help Show help and usage information
If validator 1 fails with error, each next validator will append same error message, even though error message was not set. This leads to many duplicate messages in dotnet new case as it is using many validators. It was not the case using previous API.
Imo if error message was not changed, it should not be probably added next time as new error then, because it is same error and should not be reported more then once.
Activity
vlada-shubina commentedon Jan 10, 2022
root cause seems to be this chunk of code:
command-line-api/src/System.CommandLine/Parsing/ParseResultVisitor.cs
Lines 326 to 335 in d00241c
it will repeat all the previous error messages for all remaining validators.
jonsequitur commentedon Jan 11, 2022
After looking at this a bit more closely, I'm not convinced the behavior is wrong.
The behavior you see when setting
ArgumentResult.ErrorMessagehasn't actually changed. What changed is we removed thestringreturn value from the validator delegate which now forces the use ofArgumentResult.ErrorMessage, meaning now there's only one way to display an error. This was intentional. What I didn't anticipate was that because the sameArgumentResultinstance is passed in turn to each validator, they also share a singleErrorMessagerather than each getting to contribute their own error messages. This was not intentional.Without changing the API, the old behavior can still be achieved: the second validator for example could append to the
ErrorMessagethat the previous one set. (I don't know if that's the right thing to do, but it's worth mentioning.)Another approach would be to change the API, e.g. replace the
ErrorMessageproperty with something likeAddErrorMessage, or aList<string> ErrorMessages. I'm not sure how valuable this extra level of granularity would be.vlada-shubina commentedon Jan 11, 2022
Current behavior leads to the following output when using
UseParseErrorReporting():If validator 1 fails with error, each next validator will append same error message, even though error message was not set. This leads to many duplicate messages in dotnet new case as it is using many validators. It was not the case using previous API.
Imo if error message was not changed, it should not be probably added next time as new error then, because it is same error and should not be reported more then once.
fix dotnet#1573
fix dotnet#1573