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
flag: improve clarity of "flag provided but not defined" error message #36364
Comments
/cc @dmitshur |
I think the first suggestion would be a good improvement. It improves clarity of the error message without adding complexity and special cases to the code. There isn't much precedent in the |
I don't think this change is large enough to need to go through the proposal process (https://github.com/golang/proposal#scope), so I'll make it a regular issue for now. |
Seems like all google searches of this issues come here first. :) |
All this requires is changing %s to %q in the error message. |
The message
To put it in context, it will look like this:
Instead of this:
The example with |
Change https://golang.org/cl/224017 mentions this issue: |
Change https://golang.org/cl/224018 mentions this issue: |
Version: go1.13.5
I have a code snippet with a series of flags:
After building, if this is executed in a bash shell:
./script "-flag1 value1" "-flag2 value2"
the output I see is this:
Now, this code doesn't work because of the quotes in the bash command and removing the quotes makes this work exactly as expected. This took me a while to debug as I wasn't able to initially interpret from
flag provided but not defined: -flag1 value1
that the program was interpreting-flag1 value1
as the literal flag, as opposed to the flag and the value.I might suggest one of two fixes:
Slightly modify the error message from
flag provided but not defined: FLAG
to
flag "FLAG" provided but not defined
Add logic to detect common potential mistakes such as:
The text was updated successfully, but these errors were encountered: