From 5533699ec5824c8df3c6a9a0fac05a058a626de2 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 30 Jan 2026 00:04:01 +0800 Subject: [PATCH] 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 --- nvm.sh | 8 +++++++- ...inferred version shows the inferred message | 18 ++++++++++++++++++ ...stalled version shows the requested version | 13 +++++++++++++ ...-exec' should display required node version | 1 - 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100755 test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message create mode 100755 test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version diff --git a/nvm.sh b/nvm.sh index 4e8448e..9107746 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3750,7 +3750,13 @@ nvm() { fi if ! nvm_is_version_installed "${VERSION}"; then - nvm_err "${VERSION} version is not installed..." + local REQUESTED_VERSION + REQUESTED_VERSION="${PATTERN}" + if [ "_${VERSION}" != "_N/A" ] && [ "_${VERSION}" != "_${PATTERN}" ]; then + nvm_err "Version '${VERSION}' (inferred from ${PATTERN}) is not installed." + else + nvm_err "Version '${REQUESTED_VERSION}' is not installed." + fi return fi diff --git a/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message b/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message new file mode 100755 index 0000000..2a08076 --- /dev/null +++ b/test/fast/Running 'nvm uninstall' with an inferred version shows the inferred message @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +\. ../../nvm.sh +\. ../common.sh + +VERSION='v0.0.1' +PATTERN='0.0' + +mkdir -p "${NVM_DIR}/${VERSION}" + +set +ex # needed for stderr +RETURN_MESSAGE="$(nvm uninstall "${PATTERN}" 2>&1 || echo)" +set -ex +EXPECTED_MESSAGE="Version '${VERSION}' (inferred from ${PATTERN}) is not installed." + +[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ] diff --git a/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version b/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version new file mode 100755 index 0000000..25ba202 --- /dev/null +++ b/test/fast/Running 'nvm uninstall' with an uninstalled version shows the requested version @@ -0,0 +1,13 @@ +#!/bin/sh + +set -ex + +\. ../../nvm.sh +\. ../common.sh + +set +ex # needed for stderr +RETURN_MESSAGE="$(nvm uninstall 22 2>&1 || echo)" +set -ex +EXPECTED_MESSAGE="Version '22' is not installed." + +[ "${RETURN_MESSAGE}" = "${EXPECTED_MESSAGE}" ] diff --git a/test/fast/Running 'nvm-exec' should display required node version b/test/fast/Running 'nvm-exec' should display required node version index 1aef91b..0d24e56 100755 --- a/test/fast/Running 'nvm-exec' should display required node version +++ b/test/fast/Running 'nvm-exec' should display required node version @@ -5,7 +5,6 @@ set -x \. ../../nvm.sh cleanup() { rm -f .nvmrc; } - die () { echo "$@" ; cleanup ; exit 1; } NVM_TEST_VERSION=v0.42