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

"Flag provided but not defined" doesn't give enough details #852

Closed
coilysiren opened this issue Aug 10, 2019 · 15 comments
Closed

"Flag provided but not defined" doesn't give enough details #852

coilysiren opened this issue Aug 10, 2019 · 15 comments
Labels
help wanted please help if you can! kind/documentation describes a documentation update status/confirmed confirmed to be valid, but work has yet to start
Milestone

Comments

@coilysiren
Copy link
Member

coilysiren commented Aug 10, 2019

"Flag provided but not defined" doesn't give enough details for end users who aren't specifically aware of how CLIs work. I get a lot of bug reports that are "I got this obscure error message, and I'm not sure what to do".

See also

@coilysiren coilysiren added kind/documentation describes a documentation update status/confirmed confirmed to be valid, but work has yet to start labels Aug 10, 2019
@coilysiren coilysiren assigned coilysiren and unassigned coilysiren Aug 10, 2019
@coilysiren coilysiren added the help wanted please help if you can! label Aug 10, 2019
@ghost
Copy link

ghost commented Aug 12, 2019

I'd like an opportunity to tackle this one. working on it now

@coilysiren
Copy link
Member Author

@Zohvek yay cool! 🎉

@coilysiren coilysiren assigned ghost Aug 12, 2019
@coilysiren coilysiren added status/claimed someone has claimed this issue and removed help wanted please help if you can! status/confirmed confirmed to be valid, but work has yet to start labels Aug 17, 2019
@ghost ghost removed their assignment Aug 26, 2019
@coilysiren coilysiren added help wanted please help if you can! status/confirmed confirmed to be valid, but work has yet to start and removed status/claimed someone has claimed this issue labels Aug 29, 2019
@coilysiren
Copy link
Member Author

Moving this one back to help wanted 📝

@arashout
Copy link

I can try working on this, but what kind of error exactly would be more explicit than this?

Something like:
"The flag 'v' was passed but you did not define an associated flag in the configuration for 'v'" ?

I'm not sure that is any better? Do you have any suggestions @lynncyrin ?

@stale
Copy link

stale bot commented Jan 21, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jan 21, 2020
@coilysiren
Copy link
Member Author

"The flag 'v' was passed but you did not define an associated flag in the configuration for 'v'" ?

This is closer, but still probably not verbose enough. There's also a few words / phrases that are likely to trip people up here, specifically:

  • "was passed"
  • "define an associated flag"
  • "you did not define"

^ those all have meaning for CLI authors, but are likely not very understable for many CLI users. In particular there's the "you did not define", which isn't true from the PoV of users.

Working from those points, here's my suggested error message:

"You input the flag v but the y app does not accept that flag as an input."

the changes look like this:

  • "was passed" => "you input"
  • "define an associated flag" => "does not accept that flag"
  • "you did not define" => "the y app"

@stale
Copy link

stale bot commented Jan 21, 2020

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jan 21, 2020
@coilysiren
Copy link
Member Author

coilysiren commented Jan 21, 2020

I'm also vaguely skeptical that the casual user will know what the word "flag" means, so it might be better to remove that word from the error message entirely. On a related note, the "app" term only likely makes sense if you're a CLI author. So I'm thinking about an error message like this

"You input -v but the CLI y does not accept -v as an input."

@rliebz
Copy link
Member

rliebz commented Jan 21, 2020

A few examples of existing CLIs with error messages:

  • sed: sed: illegal option -- j
  • awk: awk: unknown option -j ignored
  • vim: Unknown option argument: "-j"
  • emacs: Unknown option ‘-j’
  • go: flag provided but not defined: -j
  • git: unknown option: -j
  • python: Unknown option: -j
  • pip: no such option: -j
  • node: /usr/local/bin/node: bad option: -j
  • docker: unknown shorthand flag: 'j' in -j

Fun fact: No CLI that I tried accepted a -j flag.

The word flag is almost always referred to as an option, so we should follow that example.
I don't think things like including the CLI name are necessary, since users already have that information, but a handful of tools do include it.

I'd stick with the most common pattern and probably just do unknown option: -j.

@coilysiren
Copy link
Member Author

I'd stick with the most common pattern and probably just do unknown option: -j

Your appraisal of the landscape is a good one 👍 That said, changing the error message to unknown option: -j would likely lead to a large increase in the amount of time I spent supporting users with this problem 😆

So what I would like to see here is some capability that allows CLI authors to provide their own error messages for all of our errors.

@rliebz
Copy link
Member

rliebz commented Jan 24, 2020

I personally think there's value in a shorter error message compared to what we currently have. It may be confusing because it offers information that's irrelevant to the person trying to debug, rather than not offering enough context.

Regarding providing different error messages, I agree, that functionality is necessary. It looks like the OnUsageError field should be the current solution, but unfortunately it does not cover all usage scenarios. It handles flag provided but not defined: -fake-flag, flag needs an argument: -arg-flag, invalid value "foo" for flag -int-flag: parse error, but not No help topic for 'fake-cmd'. Not sure what other usage errors might exist.

@stale
Copy link

stale bot commented Apr 23, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Apr 23, 2020
@stale
Copy link

stale bot commented May 23, 2020

Closing this as it has become stale.

@stale stale bot closed this as completed May 23, 2020
@dangspaceiq
Copy link

I have an error like this:
Incorrect Usage: flag provided but not defined: -apikey

but the apiKey is provide as requested by the documentation! And I can not find any info of what is really the cause.

@meatballhat meatballhat reopened this Apr 22, 2022
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 22, 2022
@dearchap
Copy link
Contributor

Duplicate of #427

@dearchap dearchap marked this as a duplicate of #427 Oct 27, 2022
@dearchap dearchap closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted please help if you can! kind/documentation describes a documentation update status/confirmed confirmed to be valid, but work has yet to start
Projects
None yet
Development

No branches or pull requests

6 participants