Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message isn't passed through #417

Open
EmmaZhu opened this issue Feb 28, 2017 · 1 comment
Open

Error message isn't passed through #417

EmmaZhu opened this issue Feb 28, 2017 · 1 comment

Comments

@EmmaZhu
Copy link

EmmaZhu commented Feb 28, 2017

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?

@nemec
Copy link
Collaborator

nemec commented Mar 4, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants