Skip to content

Commit

Permalink
Enable Bash's inherit_errexit (#1655)
Browse files Browse the repository at this point in the history
By default Bash subshells (including command substitutions) do not
inherit exit on error from the caller. This can cause surprises when
functions are called from within command substitutions whose error
handling is relying upon exit on error. For example, this cause error
handling not to work as expected in the upcoming Python version
handling reimplementation.

However, as of Bash 4.4 this can be changed by enabling `inherit_errexit`.
(The oldest Bash on our supported stacks is 5.0.)

See:
https://www.shellcheck.net/wiki/SC2311
https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

GUS-W-16899232.
  • Loading branch information
edmorley authored Oct 3, 2024
1 parent 02f8ec0 commit 92633fc
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Improved the robustness of buildpack error handling by enabling `inherit_errexit`. ([#1655](https://github.com/heroku/heroku-buildpack-python/pull/1655))

## [v258] - 2024-10-01

Expand Down
1 change: 1 addition & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# shellcheck disable=SC2250 # TODO: Use braces around variable references even when not strictly required.

set -euo pipefail
shopt -s inherit_errexit

# Note: This can't be enabled via app config vars, since at this point they haven't been loaded from ENV_DIR.
if [[ "${BUILDPACK_XTRACE:-0}" == "1" ]]; then
Expand Down
1 change: 1 addition & 0 deletions bin/detect
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See: https://devcenter.heroku.com/articles/buildpack-api

set -euo pipefail
shopt -s inherit_errexit

BUILD_DIR="${1}"

Expand Down
1 change: 1 addition & 0 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See: https://devcenter.heroku.com/articles/buildpack-api

set -euo pipefail
shopt -s inherit_errexit

BUILD_DIR="${1}"

Expand Down
1 change: 1 addition & 0 deletions bin/report
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# when developing run `make compile` in this repo locally, which runs `bin/report` too.

set -euo pipefail
shopt -s inherit_errexit

CACHE_DIR="${2}"

Expand Down
1 change: 1 addition & 0 deletions bin/test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# See: https://devcenter.heroku.com/articles/testpack-api

set -euo pipefail
shopt -s inherit_errexit

# The absolute path to the root of the buildpack.
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)
Expand Down
1 change: 1 addition & 0 deletions builds/build_python_runtime.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail
shopt -s inherit_errexit

PYTHON_VERSION="${1:?"Error: The Python version to build must be specified as the first argument."}"
PYTHON_MAJOR_VERSION="${PYTHON_VERSION%.*}"
Expand Down
1 change: 1 addition & 0 deletions builds/test_python_runtime.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

set -euo pipefail
shopt -s inherit_errexit

ARCHIVE_FILEPATH="${1:?"Error: The filepath of the Python runtime archive must be specified as the first argument."}"

Expand Down
1 change: 1 addition & 0 deletions etc/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# shellcheck disable=SC2250 # TODO: Use braces around variable references even when not strictly required.

set -euo pipefail
shopt -s inherit_errexit

BP_NAME=${1:-"heroku/python"}

Expand Down

0 comments on commit 92633fc

Please sign in to comment.