-
Couldn't load subscription status.
- Fork 881
rkt: use exit status 2 to report usage errors #2149
Conversation
An obsolete CoreOS test was erroneously passing:
Error: unknown command "install" for "rkt"
Run 'rkt --help' for usage.
2016-02-08T00:57:26Z kola: --- PASS: coreos.rkt.install
|
LGTM |
| // os.Exit(0) | ||
|
|
||
| cmdRkt.Execute() | ||
| if err := cmdRkt.Execute(); err != nil && cmdExitCode == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something more specific we can check error against? might there not be false positives here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also really it would be nice to handle all non-nil errors (I know we were previously just ignoring but since you're going part of the way there..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to do anything with the error since cobra will have already logged it. As far as I can tell any errors indicate that cobra did not execute a command so there isn't any false positives. As such the check for cmdExitCode == 0 is probably not needed but I included it just in case there was ever a code path where cmdExitCode got set to some other code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One improvement that this points out is that it would be nice if cobra itself had an option to abort the program itself on errors. Also it is weird that cobra returns a nil error if there is no runnable command (e.g. running rkt without any arguments), internally it treats rkt and rkt help as identical commands despite the first being a usage error and the second being valid.
|
If you want to be more explicit about behavior and not depend on cobra logging errors and dumping usage we can handle that explicitly and set cmd.SilenceErrors and cmd.SilenceUsage |
|
I think it's fine the way it is now. @jonboulle? |
|
no strong feelings, do what you think is best |
rkt: use exit status 2 to report usage errors
An obsolete CoreOS test was erroneously passing: