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

Fix set -e fails from env hooks #1179

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

triarius
Copy link
Contributor

@triarius triarius commented Aug 8, 2023

In POSIX shells, set -e is not respected in certain contexts. One of these is: if it is in a function that is called on the left of a ||.

See https://stackoverflow.com/questions/19789102/why-is-bash-errexit-not-behaving-as-expected-in-function-calls

We previously attempted to run this script in a function and exit status 2 if there was an error, but this was not working due to the above. Since it was not working, I took the liberty to change the exit code. Exit code 2 is too overloaded in my opinion.

I chose 53. This number looks like "S3", failure to network with which, could be the source of some transient failure of this hook.

I recommend review with whitespace changes hidden.

@triarius triarius changed the title Fix set -e fails from env hooks Fix set -e fails from env hooks Aug 8, 2023
In POSIX shells, `set -e` is not respected in certain contexts. One of
these is if it is in a function that is called on the left of a `||`.

See https://stackoverflow.com/questions/19789102/why-is-bash-errexit-not-behaving-as-expected-in-function-calls

We previously attempted to run this script in a function and exit status 2 if there was an error, but this was not working due to the above.
Since it was not working, I took the liberty to change the exit code. Exit code 2 is too overloaded in my opinion.
I chose 53. This number looks like "S3", failure to network with which could be the source of some transient failure of this hook.
@triarius triarius force-pushed the pdp-1434-fix-set-e-fails-from-env-hooks branch from ff50217 to 798633b Compare August 8, 2023 22:21
@triarius triarius requested a review from a team August 8, 2023 23:10
Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

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

LGTM 🥦

@triarius triarius merged commit 4625374 into main Aug 9, 2023
@triarius triarius deleted the pdp-1434-fix-set-e-fails-from-env-hooks branch August 9, 2023 00:43
lucaswilric added a commit that referenced this pull request Mar 4, 2024
When we introduced the `environment` hook error trap in #1179, we set it to
propagate into all `source`-d plugin environment hooks. Unfortunately, this
breaks the `retry` function in the ECR plugin's environment hook (which runs
a command and then checks the exit code to determine whether to retry) by
interrupting execution before the exit code can be checked.

Repro: buildkite-plugins/ecr-buildkite-plugin#101

Fix by temporarily unsetting `-E`, stopping propagation of the trap command
into the plugin environment hook.
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.

2 participants