Skip to content

Commit 0b4c1e1

Browse files
committed
Ensure that nvm run 0.12 --version errors out sensibly when 0.12 isn't installed.
1 parent e1b7496 commit 0b4c1e1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

nvm.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ nvm() {
12711271
provided_version=$1
12721272
if [ -n "$provided_version" ]; then
12731273
VERSION="$(nvm_version "$provided_version")"
1274-
if [ "_$VERSION" = "_N/A" ]; then
1274+
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then
12751275
provided_version=''
12761276
if [ $has_checked_nvmrc -ne 1 ]; then
12771277
nvm_rc_version && has_checked_nvmrc=1
@@ -1290,16 +1290,20 @@ nvm() {
12901290
local ARGS
12911291
ARGS="$@"
12921292
local OUTPUT
1293+
local EXIT_CODE
12931294

1294-
if [ "$NVM_IOJS" = true ]; then
1295+
if [ "_$VERSION" = "_N/A" ]; then
1296+
echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2
1297+
EXIT_CODE=1
1298+
elif [ "$NVM_IOJS" = true ]; then
12951299
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")"
12961300
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs "$ARGS")"
1301+
EXIT_CODE="$?"
12971302
else
12981303
echo "Running node $VERSION"
12991304
OUTPUT="$(nvm use "$VERSION" >/dev/null && node "$ARGS")"
1305+
EXIT_CODE="$?"
13001306
fi
1301-
local EXIT_CODE
1302-
EXIT_CODE="$?"
13031307
if [ -n "$OUTPUT" ]; then
13041308
echo "$OUTPUT"
13051309
fi
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
4+
die () { echo $@ ; exit 1; }
5+
6+
. ../../../nvm.sh
7+
8+
[ "$(nvm run 0.2 --version 2>&1)" = "v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly"
9+
[ "$(nvm run iojs-0.2 --version 2>&1)" = "iojs-v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly"

0 commit comments

Comments
 (0)