Tyrrrz/CliFx

In the command argument validation failure message, the value provided for the parameter is always blank/empty

andrewkolos opened this issue · 3 comments

When a validator for a command argument returns an error result, the console emits a message that gives the value it was provided for that parameter as well as an error message provided by the validator. However, the app lists the value provided as blank. See the first line of the output below.

Command:
book add ijwef --author asbeb

Output:

Value provided for parameter <title>:
Hello I am an error
Description
  Add a book to the library.

Usage
  dotnet CliFx.Demo.dll book add <title> --author <value> [options]

Parameters
* title             Book title.

Options
* -a|--author       Book author.
  -p|--published    Book publish date. Default: "07/14/1954 19:24:40 +00:00".
  -n|--isbn         Book ISBN. Default: "905-83-85944-51-7".
  -h|--help         Shows help text.

You can demo the issue by cloning this fork and running the debug for the CliFx.Demo project.

It looks like the error message is incorrect and was accidentally truncated. It's supposed to say Value provided for parameter <title> is invalid: with the following line being the reason. It was never meant to actually print the value. That said, it may be a good idea to align this if other errors do print it.

Relevant:

internal static CliFxException ValidationFailed(
CommandParameterSchema parameter,
IReadOnlyList<ValidationResult> failedResults)
{
var message = $@"
Value provided for parameter {parameter.GetUserFacingDisplayString()}:
{failedResults.Select(r => r.ErrorMessage).JoinToString(Environment.NewLine)}";
return new CliFxException(message.Trim());
}
internal static CliFxException ValidationFailed(
CommandOptionSchema option,
IReadOnlyList<ValidationResult> failedResults)
{
var message = $@"
Value provided for option {option.GetUserFacingDisplayString()}:
{failedResults.Select(r => r.ErrorMessage).JoinToString(Environment.NewLine)}";
return new CliFxException(message.Trim());
}

Wording issue fixed in #94

Note however that the current value still isn't shown in the error.