Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set -e: nvm install lts/[anything] fails #1394

Closed
bjaspan opened this issue Feb 9, 2017 · 2 comments
Closed

set -e: nvm install lts/[anything] fails #1394

bjaspan opened this issue Feb 9, 2017 · 2 comments
Assignees
Labels
bugs Oh no, something's broken :-(

Comments

@bjaspan
Copy link

bjaspan commented Feb 9, 2017

  • Operating system and version: Linux

  • nvm debug output:

nvm --version: v0.33.0
$SHELL: /bin/bash
$HOME: /Users/bjaspan
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v7.4.0
which node: $NVM_DIR/versions/node/v7.4.0/bin/node
which iojs:
which npm: $NVM_DIR/versions/node/v7.4.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v7.4.0
npm root -g: $NVM_DIR/versions/node/v7.4.0/lib/node_modules
  • nvm ls output:
         v6.9.5
->       v7.4.0
default -> node (-> v7.4.0)
node -> stable (-> v7.4.0) (default)
stable -> 7.4 (-> v7.4.0) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.9.5)
lts/argon -> v4.7.3 (-> N/A)
lts/boron -> v6.9.5
  • How did you install nvm? (e.g. install script in readme, homebrew):

Unsure

  • What steps did you perform?

nvm install lts/boron, after running "set -e" in the shell.

  • What happened?

nvm install displayed nvm_ensure_default_set: a version is required and exited with non-zero status.

  • What did you expect to happen?

The lts/boron version should have been installed and nvm install should have exited with zero status.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

No.

  • More analysis:

I ran "nvm install lts/boron" in a Bash script with set -e and set -x. I traced through the "nvm install lts/boron" output, following along in the source of the nvm shell function. I discovered a bug in the nvm install command.

  • When you choose install an lts version, it sets the internal "provided_version" variable to the empty string.
  • At the end of the install command, it runs nvm_ensure_default_set "$provided_version". This fails with an error message, "nvm_ensure_default_set: a version is required", which we see in the output, and causes that function to return 1.
  • Because the script is being executed with "set -e", when nvm_ensure_default_set returns 1, it is considered an error and the script exits.

To reproduce, uninstall lts/boron, then install it with set -e enabled, and check that the exit status is 1, whereas if you uninstall it and install it again with set -e disabled, the exit status is zero (the error message is displayed in either case).

The workaround is to use nvm install v6.9.5, which is the version lts/boron actually maps to. This avoids the bug in nvm install, so provided_version remains set, and nvm_ensure_default_set succeeds, and the script exits with status 0 even with set -e.

@ljharb
Copy link
Member

ljharb commented Feb 9, 2017

Just to clarify, if you don't have set -e set, everything works with nvm install lts/boron?

Thanks, I want nvm to work with set -e set, but there are still a number of places where it doesn't. I'll look into it.

@ljharb ljharb added the bugs Oh no, something's broken :-( label Feb 9, 2017
@ljharb ljharb self-assigned this Feb 9, 2017
@bjaspan
Copy link
Author

bjaspan commented Feb 9, 2017

It works, but it outputs the error message nvm_ensure_default_set: a version is required before succeeding.

@ljharb ljharb changed the title nvm install lts/[anything] fails set -e: nvm install lts/[anything] fails Feb 12, 2017
@ljharb ljharb closed this as completed in affcc50 Feb 12, 2017
edwmurph pushed a commit to edwmurph/nvm that referenced this issue Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs Oh no, something's broken :-(
Projects
None yet
Development

No branches or pull requests

2 participants