dotnet / dotnet/command-line-api
More meaningful error message when Option<type> SetDefaultValue mismatched
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
If I have a Command with a sub command all setup and working, and then I add an extra option, but you've made a typo (copy/paste).
```
var uploadPrefixOption = new Option("--uploadprefix", "prefix for the zip file") //Note the incorrect type should be string
{
IsRequired = false
};
uploadPrefixOption.SetDefaultValue("backup");
backupCommand.AddOption(uploadPrefixOption);
```
when
```
return await rootCommand.InvokeAsync(args);
```
actually runs, I get an error of :
```
Unhandled exception: System.ArgumentException: The SetHandler call for command 'backup' is missing an Argument or Option for the parameter at position 4. Did you mean to pass one of these?
Option --name
```
at runtime.
The error is actually coming from the incorrect type being used for `uploadPrefixOption.SetDefaultValue("backup")`.
But the message leads you to the `--name` parameter, which is actually a bit of a redherring.
Would it be possible to throw the `ArgumentException` (or similar) on the `SetDefaultValue` because that's where the error actually is.
Contributor guide
Assessment
This issue has not been assessed yet.