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

how to use exit codes #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

willr3
Copy link
Collaborator

@willr3 willr3 commented Oct 14, 2022

No description provided.

@willr3 willr3 requested a review from rvansa October 14, 2022 13:33
There are, however, times when a commands exit code provides important information. In those cases, we have two ways to work with exit codes.

== Stop on errors
The first option is to enable exit code checking with either the `-x` ro `--exitCode` command line argument or adding `check-exit-code` to the `settings`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

or


== Specific exit values

qDup has built in support for zero and non-zero exit codes but a command can return any valid integer as an exit code and some commands provide error information based on the exit number. qDup does not have native support for filtering the exit code but we can add `echo $?` to our scripts the same way we would check the exit code if we were manually runnin commands in an ssh terminal.
Copy link
Collaborator

Choose a reason for hiding this comment

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

running

Copy link
Member

@rvansa rvansa left a comment

Choose a reason for hiding this comment

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

How does qDup handle exit codes from piped commands? What would this print?

- sh: false | true
- sh: echo $?

Would pipefail work in qDup context?

- sh: set -o pipefail

settings:
check-exit-code: true
```
Exit code checking will automatically check the exit code of all `sh` commands that end with the default qDup prompt. We don't check the exit code of commands that end with a prompt from `add-prompt` because those commands are typically in a sub-shell that may not support exit codes. qDup will then abort if the exit code is non-zero. This is a very strict way to enforce exit codes and most scripts probably are not written to consider exit codes.
Copy link
Member

Choose a reason for hiding this comment

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

Could you also do

- sh:
    command: maybe_fail
    check-exit-code: true

or do you have to do this?

- sh: maybe_fail || echo "__command_failed__"
  then:
  - regex: "__command_failed__"
    then:
    - abort: command failed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

both should work to end the run if maybe_fail had a non-zero exit code

#> echo $?
127
```
There are, however, times when a commands exit code provides important information. In those cases, we have two ways to work with exit codes.
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't say "two ways to work with exit codes" because these are not really 'generic' ways. Rather sum it up as "abort on non-zero" and "process exit code as text" or something similar.

@rvansa
Copy link
Member

rvansa commented Dec 16, 2022

Bump, is this going to be improved any further?

@johnaohara
Copy link
Member

@willr3 is there any more to add to this doc?

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

Successfully merging this pull request may close these issues.

4 participants