mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-03 11:34:50 +08:00
[Fix] nvm_install_binary: return failure when binary download fails with -b
When `nosource=1` (the `-b` flag) and binary download fails, the function returned 0 (success) instead of a non-zero exit code, masking the installation failure.
Bug introduced in 4fdef427e4 / #2439.
This commit is contained in:
2
nvm.sh
2
nvm.sh
@@ -2374,7 +2374,7 @@ nvm_install_binary() {
|
|||||||
# Read nosource from arguments
|
# Read nosource from arguments
|
||||||
if [ "${nosource-}" = '1' ]; then
|
if [ "${nosource-}" = '1' ]; then
|
||||||
nvm_err 'Binary download failed. Download from source aborted.'
|
nvm_err 'Binary download failed. Download from source aborted.'
|
||||||
return 0
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
nvm_err 'Binary download failed, trying source.'
|
nvm_err 'Binary download failed, trying source.'
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
|
|||||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm_install_binary node std 8.0.0 1 2>/dev/null; echo $?)"
|
||||||
|
[ "${EXIT_CODE}" = "2" ] || die "Expected exit code 2 when nosource=1 and binary fails, got ${EXIT_CODE}"
|
||||||
|
|
||||||
# Unit test to check if the function errors out when the flag is set
|
# Unit test to check if the function errors out when the flag is set
|
||||||
OUTPUT="$(nvm_install_binary node std 8.0.0 0 2>&1)"
|
OUTPUT="$(nvm_install_binary node std 8.0.0 0 2>&1)"
|
||||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||||
|
|||||||
Reference in New Issue
Block a user