go: flag: clean up error message
What version of Go are you using (go version
)?
go version go1.9.7 linux/amd64 (but it affects basically all versions of go).
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
GOHOSTARCH=“amd64” GOHOSTOS=“linux”
What did you do?
Provide a non-numerical input for an integer flag yields the following error:
invalid value "donut" for flag -cpu-quota: strconv.ParseInt: parsing "donut": invalid syntax
What did you expect to see?
--cpuquota is expecting an integer
Something more user-friendly. Currently, the error message must be interpreted by the user and should guide users a bit more in a direction to solve the issue. See https://github.com/projectatomic/buildah/issues/673 as an example.
What did you see instead?
invalid value "donut" for flag -cpu-quota: strconv.ParseInt: parsing "donut": invalid syntax
Proposal
I want to suggest two options:
- Update the error messages (e.g., for integer flags https://golang.org/src/flag/flag.go?s=8120:8324#L912).
- Expose public error types (e.g.,
ErrInvalidValue
andErrInvalidBoolen
) that can be used by users of theflag
package (e.g.,urfave/cli
).
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (15 by maintainers)
If you want to look at the registered flags and make a new flag parser, do that. Don’t try to parse the parser errors - just do a fresh parse. See rsc.io/getopt for an example.