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

The unknown commnd error should be easily recognizable #1077

Closed
JAicewizard opened this issue Apr 2, 2020 · 8 comments
Closed

The unknown commnd error should be easily recognizable #1077

JAicewizard opened this issue Apr 2, 2020 · 8 comments

Comments

@JAicewizard
Copy link

Currently an unknown command error is indistinguishable from any other error from within cobra, so it is hard to differentiate between actual errors, and the user mistyping something.

@wfernandes
Copy link
Collaborator

@JAicewizard Could you provide some more details on what errors seem indistinguishable?

Is this something that suggestions could help with?
https://github.com/spf13/cobra#suggestions-when-unknown-command-happens

@JAicewizard
Copy link
Author

when running rootCmd.Execute() it returns an error when it encounters an unknown command, even though the error is already handled gracefully within cobra itself.
In my program I panic when I encounter an error from cobra, which is sensible since there is no graceful way to handle errors in starting my application.
But there is no way to differentiate between errors that are already gracefully handled and I shouldn't care about, like unknown command, and ones that are not already handled and I should panic for.
To me it seams non-logical to return already handled errors anyway, everything went as planned and the user mistake has already been handled properly, no need to pass it up t be handled there too.

@jharshman
Copy link
Collaborator

@JAicewizard, it seems pretty common to me to return an error in the case of an unknown command. Much like many other CLIs, when they are misused, an error and usage message is returned to the caller.

Are you returning errors to the caller with RunE ?

@JAicewizard
Copy link
Author

@jharshman I dont use RunE, and usually in go once the error has been handled properly it doesn't get propagated up. The rootCmd.Execute() ran succesfullly, it didnt encounter any unrecoverable errors. It did encounter a problem but it has already been handled, and thus the caller doesnt have to take care of it anymore. Returning an err implies that the caller has to deal with it because it hasnt been dealth with yet.

@jharshman
Copy link
Collaborator

jharshman commented Apr 7, 2020

@JAicewizard , I understand where you're coming from. However, in this case, the correct response to an unknown command error is to return it to the user. This is common behavior among other CLI utilities.

@github-actions
Copy link

github-actions bot commented Jun 7, 2020

This issue is being marked as stale due to a long period of inactivity

@wfernandes
Copy link
Collaborator

I think we can close this issue if this is not intended behavior. WDYT? @jharshman

@jharshman
Copy link
Collaborator

Agreed, focus should instead be on consistent error propagation as is being discussed in #1156.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants