-
Notifications
You must be signed in to change notification settings - Fork 350
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
Better error messages for parsing errors #269
Comments
@ck-schmidi I also would like this, but instead of imposing a formatted string, I would prefer a sentinel error I can check and format myself. type FlagParseError struct {
// The flag being parsed and all it's context.
Flag *Flag
// The error thrown by the parse/set function
Err error
// The input value
Value string
} Then the caller can check if |
I just bumped into this through https://github.com/Tufin/oasdiff which uses https://github.com/spf13/cobra. Running:
Returns:
For more details see Tufin/oasdiff#482. |
I second this. spf13 shouldn't be returning internal programmer targeted errors ("strconv.ParseBool..."). It should return a simpler end user targeted error. |
We still have an old open issue for our CLI tool which is kind of a cosmetic thing, but it's still annoying and we would really like to have it fixed somehow.
If the parsing of a flag fails this error message gets created:
invalid argument "test" for "-w, --warning" flag: strconv.ParseInt: parsing "test": invalid syntax
For us, exposing internal function names to our users is not really an option.
There was also a discussion on the same topic for the golang stdlibrary. And they fixed the error messages
They went from:
invalid boolean value "3" for -debug: strconv.ParseBool: parsing "3": invalid syntax
to
invalid boolean value "3" for -debug: parse error
which doesn't expose any technical details to the users.
It would be nice if we could a similar way for the
pflag
package.According to my example one proposal would be:
invalid argument "test" for "-w, --warning" flag: parse error
or even better (type in the front part of the message):
invalid integer value "test" for "-w, --warning" flag: parse error
Another approach could be providing a format function, so users of the
pflag
library can inject a format function for a customized formatting of parsing errors.I checked all old issues and didn't find any similar problems. It's just a proposal and I would spend time providing a patch for it, but maybe some of you have thoughts on it.
The text was updated successfully, but these errors were encountered: