From 74544c12f4badb17aa1904b33b7b0f0ddfb61c41 Mon Sep 17 00:00:00 2001 From: Oikantik Basu <140976895+Golden007-prog@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:09:58 +0530 Subject: [PATCH] [Fix] `nvm install`: explain native Windows curl write failures Refs #3391. --- nvm.sh | 10 ++++ ..._download_artifact Windows curl diagnostic | 56 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 test/fast/Unit tests/nvm_download_artifact Windows curl diagnostic diff --git a/nvm.sh b/nvm.sh index 6a6da3ef..b839d631 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4389,10 +4389,20 @@ nvm_download_artifact() { UNVERIFIED_TARBALL="${UNVERIFIED_DIR}/${SLUG}.${COMPRESSION}" nvm_err "Downloading $(nvm_sanitize_url "${TARBALL_URL}")..." + local DOWNLOAD_STATUS # stdout is reserved for the tarball path, so nothing the downloader prints may reach it nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${UNVERIFIED_TARBALL}" >&2 || { + DOWNLOAD_STATUS=$? command rm -rf "${UNVERIFIED_DIR}" "${tmpdir}" nvm_err "download from $(nvm_sanitize_url "${TARBALL_URL}") failed" + # curl returns 23 when it cannot write the output file. + if [ "${DOWNLOAD_STATUS}" -eq 23 ] && [ "$(nvm_get_os)" = 'win' ]; then + case "$(command curl -V 2>/dev/null)" in + 'curl '*'(Windows)'*) + nvm_err 'Native Windows curl may not be able to write POSIX paths. Install curl for your shell environment and put it first on PATH.' + ;; + esac + fi return 4 } diff --git a/test/fast/Unit tests/nvm_download_artifact Windows curl diagnostic b/test/fast/Unit tests/nvm_download_artifact Windows curl diagnostic new file mode 100755 index 00000000..4305f681 --- /dev/null +++ b/test/fast/Unit tests/nvm_download_artifact Windows curl diagnostic @@ -0,0 +1,56 @@ +#!/bin/sh + +: nvm.sh +NVM_ENV=testing \. ../../../nvm.sh +\. ../../common.sh + +die () { echo "$@" ; exit 1; } + +WORK="$(mktemp -d "${TMPDIR:-/tmp}/nvm-windows-curl.XXXXXX")" || exit 1 +trap 'command rm -rf "${WORK}"' EXIT +NVM_DIR="${WORK}/nvm" +NVM_OFFLINE=0 + +nvm_get_mirror() { echo 'https://node.example.invalid/dist'; } +nvm_get_checksum_binary() { echo 'sha256sum'; } +nvm_get_checksum() { echo 'checksum'; } +nvm_get_os() { echo "${TEST_OS}"; } + +make_fake_curl "${WORK}/bin" 'exit "${TEST_CURL_EXIT}"' || die 'could not create curl fixture' +PATH="${WORK}/bin:${PATH}" +export PATH TEST_CURL_EXIT + +assert_download_failure() { + try_err nvm_download_artifact node binary std v20.0.0 + [ "${CAPTURED_EXIT_CODE}" = 4 ] || die "expected artifact failure (4), got ${CAPTURED_EXIT_CODE}" +} + +TEST_OS=win +TEST_CURL_EXIT=23 +VERSION_MESSAGE='curl 8.23.0 (Windows) libcurl/8.23.0 Schannel' +HINT='Install curl for your shell environment' +assert_download_failure +case "${CAPTURED_STDERR}" in + *"${HINT}"*) ;; + *) die "the native Windows curl write failure needs a diagnostic; got: ${CAPTURED_STDERR}" ;; +esac + +TEST_OS=linux +assert_download_failure +case "${CAPTURED_STDERR}" in + *"${HINT}"*) die 'the diagnostic should not appear on Linux' ;; +esac + +TEST_OS=win +VERSION_MESSAGE='curl 8.23.0 (x86_64-pc-cygwin) libcurl/8.23.0' +assert_download_failure +case "${CAPTURED_STDERR}" in + *"${HINT}"*) die 'the diagnostic should not appear with Cygwin curl' ;; +esac + +VERSION_MESSAGE='curl 8.23.0 (Windows) libcurl/8.23.0 Schannel' +TEST_CURL_EXIT=22 +assert_download_failure +case "${CAPTURED_STDERR}" in + *"${HINT}"*) die 'the diagnostic should not appear for an HTTP failure' ;; +esac