-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
cli/command: ctx cancel should not print or produce a non zero exit code #5666
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5666 +/- ##
==========================================
+ Coverage 59.13% 59.51% +0.37%
==========================================
Files 343 347 +4
Lines 29370 29408 +38
==========================================
+ Hits 17369 17503 +134
+ Misses 11029 10934 -95
+ Partials 972 971 -1 |
b6c8353
to
d7c81a3
Compare
9275a27
to
a20d0c8
Compare
@thaJeztah @vvoland do you have any concerns that would prevent this PR from getting merged? |
I'm also not sure if we should be changing the StatusError.. Rather than leaving the whole PR sitting while we try to decide, i think we can split that out and at least merge the ctx cancellation bits which are good to have and improve the ux. WDYT? |
We can separate it (it already is split up between 2 commits), but the UI will still print the error "user terminated the process" since the For example: ⋊> ~/G/cli-3 on 5f221783c ./build/docker run postgres:latest 12:49:47
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
fd674058ff8f: Pulling fs layer
1eab12a50bdf: Pulling fs layer
5a81b4aedb94: Pulling fs layer
502eeeb4a17b: Waiting
e9e19177b318: Waiting
2068838cf5fa: Waiting
45a271dbb114: Waiting
8f9ac4ec849d: Waiting
9d8b60e88ddb: Waiting
3ec4ef471804: Waiting
16d755b48cd4: Waiting
3d5d11fb541c: Waiting
d8ab5fe30360: Waiting
d19370fe7a12: Waiting
^Cdocker: user terminated the process
Run 'docker run --help' for more information
⋊> ~/G/cli-3 on 5f221783c The only option to not have You can try it for yourself, |
There are other options that aren't perfect, but work in the interim, such as @thaJeztah's solution here. Would require a pass over the codebase to look at all of the other places, but that's probably fine and something that can be done iteratively. There's always string matching too 😅 ...
if err != nil && !errdefs.IsCancelled(err) && !errors.Is(err, errCtxUserTerminated) {
... do ...
if err != nil {
// FIXME: replace this with errdefs.IsCancelled after changing StatusErr
if err.Error() != "context cancelled" {
... |
I also wrestled with this a bit and I still came to the conclusion that having it match with The "best" solution I can come up with at this point in time is to replace |
a20d0c8
to
3c2e27d
Compare
Signed-off-by: Alano Terblanche <[email protected]>
3c2e27d
to
f9c3ab4
Compare
The user might kill the CLI through a SIGINT/SIGTERM which cancels the main context we pass around. Currently the context cancel error is printed alongside any other wrapped error with a generic exit code (125). This patch improves on this behavior and prevents any error from being printed when they match `context.Cancelled`. The `cli.StatusError` error would wrap errors but not provide a way to unwrap them. This would lead to situations where `errors.Is` would not match the underlying error. Signed-off-by: Alano Terblanche <[email protected]>
f9c3ab4
to
bed4155
Compare
I've updated the code to use a new error called Now the question is:
|
Yeah, I see a few instances (~250, but could be more if importing under other names) – including @ndeloof in swarmctl – of people doing this around Github, but that's a lot smaller so I'm less concerned. I'll leave it up to @thaJeztah and folks as to how acceptable that is. Perfect is the enemy of good, and I think in projects such as these compromises need to be made sometimes to make the current situation better without breaking other things, which is why I don't think string matching as a stop-gap (that can be reverted on the next major when As long as |
Yeah I mean, there are only three options here (I'm okay choosing any of these):
Currently the last commit introduces the third option, but we can drop it and just go with option 1. |
FYI @Benehiko that |
To be clear, the best solution is clearly changing We could simply add a field to the // StatusError reports an unsuccessful exit by a command.
type StatusError struct {
Cause error
// Deprecated: use Cause instead.
Status string
StatusCode int
} And use that in the CLI codebase from now on, and then remove the |
The user might kill the CLI through a SIGINT/SIGTERM
which cancels the main context we pass around.
Currently the context cancel error is printed
alongside any other wrapped error with a generic
exit code (125).
This patch improves on this behavior and prevents
any error from being printed when they match
context.Cancelled
.The
cli.StatusError
error would wrap errors butnot provide a way to unwrap them. This would lead
to situations where
errors.Is
would not match the underlying error.Closes #5659
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)