Skip to content

Commit 5533699

Browse files
Improve uninstall error message for missing versions
Include the requested version in the uninstall error output when the target is not installed. Add a fast test to lock the behavior. Close #3767
1 parent 6d761ba commit 5533699

4 files changed

+38
-2
lines changed

nvm.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3750,7 +3750,13 @@ nvm() {
37503750
fi
37513751

37523752
if ! nvm_is_version_installed "${VERSION}"; then
3753-
nvm_err "${VERSION} version is not installed..."
3753+
local REQUESTED_VERSION
3754+
REQUESTED_VERSION="${PATTERN}"
3755+
if [ "_${VERSION}" != "_N/A" ] && [ "_${VERSION}" != "_${PATTERN}" ]; then
3756+
nvm_err "Version '${VERSION}' (inferred from ${PATTERN}) is not installed."
3757+
else
3758+
nvm_err "Version '${REQUESTED_VERSION}' is not installed."
3759+
fi
37543760
return
37553761
fi
37563762

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
\. ../../nvm.sh
6+
\. ../common.sh
7+
8+
VERSION='v0.0.1'
9+
PATTERN='0.0'
10+
11+
mkdir -p "${NVM_DIR}/${VERSION}"
12+
13+
set +ex # needed for stderr
14+
RETURN_MESSAGE="$(nvm uninstall "${PATTERN}" 2>&1 || echo)"
15+
set -ex
16+
EXPECTED_MESSAGE="Version '${VERSION}' (inferred from ${PATTERN}) is not installed."
17+
18+
[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
\. ../../nvm.sh
6+
\. ../common.sh
7+
8+
set +ex # needed for stderr
9+
RETURN_MESSAGE="$(nvm uninstall 22 2>&1 || echo)"
10+
set -ex
11+
EXPECTED_MESSAGE="Version '22' is not installed."
12+
13+
[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ]

test/fast/Running 'nvm-exec' should display required node version

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -x
55
\. ../../nvm.sh
66

77
cleanup() { rm -f .nvmrc; }
8-
98
die () { echo "$@" ; cleanup ; exit 1; }
109

1110
NVM_TEST_VERSION=v0.42

0 commit comments

Comments
 (0)