Skip to content

Commit 92633fc

Browse files
authored
Enable Bash's inherit_errexit (#1655)
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.
1 parent 02f8ec0 commit 92633fc

File tree

9 files changed

+9
-0
lines changed

9 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

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

67
## [v258] - 2024-10-01
78

bin/compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# shellcheck disable=SC2250 # TODO: Use braces around variable references even when not strictly required.
55

66
set -euo pipefail
7+
shopt -s inherit_errexit
78

89
# Note: This can't be enabled via app config vars, since at this point they haven't been loaded from ENV_DIR.
910
if [[ "${BUILDPACK_XTRACE:-0}" == "1" ]]; then

bin/detect

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See: https://devcenter.heroku.com/articles/buildpack-api
44

55
set -euo pipefail
6+
shopt -s inherit_errexit
67

78
BUILD_DIR="${1}"
89

bin/release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See: https://devcenter.heroku.com/articles/buildpack-api
44

55
set -euo pipefail
6+
shopt -s inherit_errexit
67

78
BUILD_DIR="${1}"
89

bin/report

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# when developing run `make compile` in this repo locally, which runs `bin/report` too.
1919

2020
set -euo pipefail
21+
shopt -s inherit_errexit
2122

2223
CACHE_DIR="${2}"
2324

bin/test-compile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# See: https://devcenter.heroku.com/articles/testpack-api
44

55
set -euo pipefail
6+
shopt -s inherit_errexit
67

78
# The absolute path to the root of the buildpack.
89
BUILDPACK_DIR=$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)

builds/build_python_runtime.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4+
shopt -s inherit_errexit
45

56
PYTHON_VERSION="${1:?"Error: The Python version to build must be specified as the first argument."}"
67
PYTHON_MAJOR_VERSION="${PYTHON_VERSION%.*}"

builds/test_python_runtime.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4+
shopt -s inherit_errexit
45

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

etc/publish.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# shellcheck disable=SC2250 # TODO: Use braces around variable references even when not strictly required.
33

44
set -euo pipefail
5+
shopt -s inherit_errexit
56

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

0 commit comments

Comments
 (0)