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

Added error info on non 0 and unknown exit code #867

Closed
wants to merge 1 commit into from

Conversation

olivergs
Copy link
Collaborator

When a command is executed with toolbox run and it returns a non zero exit code, if that exit code is not handled it is just ignored.

This prevents users to identify errors when executing commands in toolbox.

With this fix, the unhandled exit codes are returned as errors to give the user a better error info.

When a command is executed with toolbox run and it returns a non
zero exit code, if that exit code is not handled it is just ignored.

This prevents users to identify errors when executing commands in
toolbox.

With this fix, the unhandled exit codes are returned as errors
to give the user a better error info.
@softwarefactory-project-zuul
Copy link

Build failed.

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for converting the discussion with @fmuellner into a pull request, @olivergs !

if err != nil {
newerr = fmt.Errorf("failed to invoke command %s in container %s (Exit code: %d): %s", command[0], container, exitCode, err)
} else {
newerr = fmt.Errorf("failed to invoke command %s in container %s (Exit code: %d)", command[0], container, exitCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if enter and/or run forwarded the exit code of the requested command? eg., toolbox run false would have an exit code of 1 and toolbox run true would have 0.

I suppose, most people use the exit code programmatically because they can already see the standard error and output streams as a human. In that case, not forwarding the exit code breaks the programmability of it.

But it's hard to say without knowing the exact use-case.

Part of the complication in forwarding the exit code is that Cobra, the Go framework we use for our command line handling, only lets us return an error. See Execute in src/cmd/root.go. So, I think we will need to provide our own custom error implementation that can encapsulate an exit code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the complication in forwarding the exit code is that Cobra, the Go framework we use for our command line handling, only lets us return an error. See Execute in src/cmd/root.go. So, I think we will need to provide our own custom error implementation that can encapsulate an exit code.

We could simply stop relying on that part of Cobra and exit from directly from the commands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good to have multiple exit points spread all over the code.

Having a single consolidated exit point means that we have a well-defined place to perform clean-ups, and put breakpoints or logs for debugging.

@HarryMichal HarryMichal added this to the Release 0.1.0 milestone Oct 25, 2021
@HarryMichal HarryMichal added 7. Needs tests The work needs new test cases added 2. Host Realm The issue is related to what happens on the host machine where Toolbox is executed 2. Under The Hood Multiple areas of the app are influenced by this ticket 3. Bugfix Fixes a bug labels Dec 5, 2021
HarryMichal pushed a commit to HarryMichal/toolbox that referenced this pull request Dec 5, 2021
When a command is executed with toolbox run and it returns a non-zero
exit code, it is just ignored if that exit code is not handled. This
prevents users to identify errors when executing commands in toolbox.

With this fix, the exit codes of the invoked command are propagated
and returned by 'toolbox run'. This includes even exit codes returned
by Podman on error.

containers#867
@HarryMichal
Copy link
Member

I propose an alternative implementation of this which fully propagates the return codes of the invoked commands (including Podman): https://github.com/HarryMichal/toolbox/tree/cmd/run/return-code-propagation

HarryMichal pushed a commit to HarryMichal/toolbox that referenced this pull request Feb 21, 2022
When a command is executed with toolbox run and it returns a non-zero
exit code, it is just ignored if that exit code is not handled. This
prevents users to identify errors when executing commands in toolbox.

With this fix, the exit codes of the invoked command are propagated
and returned by 'toolbox run'. This includes even exit codes returned
by Podman on error.

containers#867
@HarryMichal
Copy link
Member

Created #1013 with the alternative implementation.

@HarryMichal
Copy link
Member

Closing in favor of #1013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. Host Realm The issue is related to what happens on the host machine where Toolbox is executed 2. Under The Hood Multiple areas of the app are influenced by this ticket 3. Bugfix Fixes a bug 7. Needs tests The work needs new test cases added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants