mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-03 11:34:50 +08:00
[Fix] nvm which: show alias name in infinite loop error message
`${2}` was empty because positional parameters had been consumed by `shift` in the argument parsing loop.
Use `${provided_version}` which holds the resolved alias name.
Bug introduced in 1c00753fd9.
This commit is contained in:
2
nvm.sh
2
nvm.sh
@@ -4374,7 +4374,7 @@ nvm() {
|
|||||||
nvm_err 'System version of node not found.'
|
nvm_err 'System version of node not found.'
|
||||||
return 127
|
return 127
|
||||||
elif [ "${VERSION}" = '∞' ]; then
|
elif [ "${VERSION}" = '∞' ]; then
|
||||||
nvm_err "The alias \"${2}\" leads to an infinite loop. Aborting."
|
nvm_err "The alias \"${provided_version}\" leads to an infinite loop. Aborting."
|
||||||
return 8
|
return 8
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
24
test/fast/Running 'nvm which' with circular alias shows alias name
Executable file
24
test/fast/Running 'nvm which' with circular alias shows alias name
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -rf "$(nvm_alias_path)/circular_test"
|
||||||
|
}
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../nvm.sh
|
||||||
|
|
||||||
|
\. ../common.sh
|
||||||
|
|
||||||
|
nvm_make_alias circular_test circular_test
|
||||||
|
|
||||||
|
try_err nvm which circular_test
|
||||||
|
EXPECTED_OUTPUT='The alias "circular_test" leads to an infinite loop. Aborting.'
|
||||||
|
[ "_${CAPTURED_STDERR}" = "_${EXPECTED_OUTPUT}" ] \
|
||||||
|
|| die "'nvm which circular_test' did not output >${EXPECTED_OUTPUT}<; got >${CAPTURED_STDERR}<"
|
||||||
|
[ "_$CAPTURED_EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${CAPTURED_EXIT_CODE}"
|
||||||
|
|
||||||
|
cleanup
|
||||||
Reference in New Issue
Block a user