Error message isn't passed through
For example, I have a customized parameter defined like following:
public class MyParameters
{
public MyParameters(string init)
{
throw new InvalidOperationException("Some error message");
}
public string Value { get; private set; }
}
I'd want to show the accurate error message when the parameter value user input is incorrect. But seems the error message is always like:
Option 'option1' is defined with a bad format.
Is there anyway I can get the error message passed through?
Can you post a minimal reproduction of the issue, with a complete options class and the args array you're passing to the compiler? Also, which version of the library are you using?
From what you've mentioned so far, and assuming you're using the version in master, I think you will need to insert your custom error text when building the help screen:
result.WithNotParsed(errs =>
{
HelpText.AutoBuild(result, help =>
{
help.AddPreOptionsLine("Some error message");
return help;
}, e => e)
.ToString()
.Dump();
});
You can do whatever you want in the first delegate to AutoBuild, including displaying custom messages.