-
Notifications
You must be signed in to change notification settings - Fork 13
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
Return non-zero exit code in case of errors #690
Conversation
LGTM thanks |
9e29bf9
to
c49448a
Compare
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.
LGTM
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.
I think we're using Run
instead of RunE
which indicates that we're relying on the os.Exit(1)
to occur in the individual cmds. I might be wrong, but I think the ExecuteContext
here only returns an error if the RunE
, PreRunE
, PostRunE
or similar "error-returning" methods return an error which we don't have any of them (AFAIK).
This change is a valid change but if we're addressing the fact that k8s commands does not exit with code 1 when they should, this won't solve that issue.
In other words, this change won't cause any behavior changes because of the current implementation.
If there's any k8s command that exits with code 0 while also facing with an error I think we should change the code for that specific cmd and call the os.Exit(1)
there (e.g.:
k8s-snap/src/k8s/cmd/k8s/k8s_status.go
Line 32 in 5fe3c27
env.Exit(1) |
@HomayoonAlimohammadi thanks for bringing this up. I did a simple check and it seemed to work fine but I'll take a closer look.
LE: I see that the commands that use |
As discussed in the standup: You both are correct. So, |
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.
LGTM. Please add a note to the error check.
e.g. // Although k8s commands typically use Run instead of RunE and handle errors directly within the command execution, this acts as a safeguard in case any are overlooked.
c49448a
to
5c77fd4
Compare
I've added another commit here, I hope that's ok.
The Run/RunE functions won't get called at all if there are argument parsing errors, so that's another reason why we need this. I've added an inline comment. |
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.
LGTM, thanks for the change!
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.
LGTM, Thanks a lot @petrutlucian94! Just some very minor comments.
At the moment, k8s and k8sd return 0 even if the command fails, which is a problem especially when used inside scripts. We'll ensure that a non-zero exit code is returned if the commands fail.
The cluster recovery command currently uses "RunE" and returns an error in case of failures. To stay consistent with other commands, we'll use "Run" and call env.Exit as part of the command callback instead of returning the errors.
5c77fd4
to
3a89bf2
Compare
* Return non-zero exit code in case of errors At the moment, k8s and k8sd return 0 even if the command fails, which is a problem especially when used inside scripts. We'll ensure that a non-zero exit code is returned if the commands fail. * Update the cluster recovery command to use cobra "Run" The cluster recovery command currently uses "RunE" and returns an error in case of failures. To stay consistent with other commands, we'll use "Run" and call env.Exit as part of the command callback instead of returning the errors.
At the moment, k8s and k8sd return 0 even if the command fails, which is a problem especially when used inside scripts.
We'll ensure that a non-zero exit code is returned if the commands fail.