Skip to content

Commit f537d00

Browse files
committed
fix(direnv): set ERR trap after definition & before use
Also, fix the return code, which was making bash4 quite sad.
1 parent 08d34a6 commit f537d00

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

.envrc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66
# If you'd like to override or set any custom environment variables, this .envrc will read a .env file at the end.
77
set -e
88

9-
# Upgrading Mac can uninstall the Command Line Tools, thus, removing our access to git
10-
# The message talks about xcrun, however, we can use the lack of git as a way to know that we need this
11-
# xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
12-
# missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
13-
if [ "$(uname -s)" == "Darwin" ] && [ ! -f "/Library/Developer/CommandLineTools/usr/bin/git" ]; then
14-
echo -e "$(tput setaf 1)\nERROR: Complete the interactive installation (10+ mins) of the Command Line Tools.$(tput sgr0)"
15-
xcode-select --install
16-
return 1
17-
fi
189

1910
SENTRY_ROOT="$(
2011
cd "$(dirname "${BASH_SOURCE[0]}")"
@@ -23,11 +14,6 @@ SENTRY_ROOT="$(
2314

2415
source "${SENTRY_ROOT}/scripts/lib.sh"
2516

26-
# XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
27-
# consequently, using "exit" anywhere will skip this notice from showing.
28-
# so need to use set -e, and return 1.
29-
trap notice ERR
30-
3117
complete_success="yup"
3218

3319
help_message() {
@@ -46,9 +32,10 @@ EOF
4632
help_message
4733
}
4834

49-
notice() {
50-
[ $? -eq 0 ] && return
35+
onerr() {
36+
ret=$?
5137
failure_message
38+
return $ret
5239
}
5340

5441
debug() {
@@ -81,6 +68,21 @@ show_commands_info() {
8168

8269
### Environment ###
8370

71+
# XXX: we can't trap bash EXIT, because it'll override direnv's finalizing routines.
72+
# consequently, using "exit" anywhere will skip this notice from showing.
73+
# so need to use set -e, and return 1.
74+
trap onerr ERR
75+
76+
# Upgrading Mac can uninstall the Command Line Tools, thus, removing our access to git
77+
# The message talks about xcrun, however, we can use the lack of git as a way to know that we need this
78+
# xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
79+
# missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
80+
if [ "$(uname -s)" == "Darwin" ] && [ ! -f "/Library/Developer/CommandLineTools/usr/bin/git" ]; then
81+
echo -e "${red}\nERROR: Complete the interactive installation (10+ mins) of the Command Line Tools.${reset}"
82+
xcode-select --install
83+
return 1
84+
fi
85+
8486
commands_to_run=()
8587

8688
# Always write stdout immediately. Very helpful for debugging

0 commit comments

Comments
 (0)