Skip to content

flag: clean up error message #26822

@vrothberg

Description

@vrothberg

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 containers/buildah#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:

  1. Update the error messages (e.g., for integer flags https://golang.org/src/flag/flag.go?s=8120:8324#L912).
  2. Expose public error types (e.g., ErrInvalidValue and ErrInvalidBoolen) that can be used by users of the flag package (e.g., urfave/cli).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions