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

nvm.sh not working with "set -e" #1062

Closed
Richie765 opened this issue Apr 16, 2016 · 7 comments
Closed

nvm.sh not working with "set -e" #1062

Richie765 opened this issue Apr 16, 2016 · 7 comments
Labels
bugs Oh no, something's broken :-( non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. shell: bash/sh

Comments

@Richie765
Copy link

I like to run most of my scripts with set -e so they terminate whenever there is a problem.

If I run the following in my .bashrc

set -e

# commands

export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh

# other commands

It will terminate during nvm.sh with an exit code. Obviously I can work around that but perhaps it could be fixed.

@ljharb
Copy link
Member

ljharb commented Apr 16, 2016

@Richie765 nvm is not supported via homebrew. If you install the latest version using the proper method (install command in the readme), does it still terminate? if so, with what exit code?

@ljharb ljharb added shell: bash/sh bugs Oh no, something's broken :-( needs followup We need some info or action from whoever filed this issue/PR. labels Apr 16, 2016
@Richie765
Copy link
Author

Ah right, Homebrew isn't supported. I'm sure you have good reason for that. It's too much work for me to install it "properly" just for testing this. It's probably a lot easier for you to do. Just call set -e just before calling nvm.sh.

For me it exits with exit code 3. The last lines of a trace are as follows:

$ cat test
#!/bin/sh

set -e
set -x

export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh
$ ./test
<cut>
+++++ command sed '
            s#/homepath/.nvm/versions/io.js/#iojs-#;
            \#/homepath/.nvm/versions/io.js# d;
            s#^/homepath/.nvm/##;
            \#^versions$# d;
            s#^versions/##;
            s#^v#node-v#;
            s#^\(iojs\)[-/]v#\1.v#;
            s#^\(node\)[-/]v#\1.v#'
+++++ sed '
            s#/homepath/.nvm/versions/io.js/#iojs-#;
            \#/homepath/.nvm/versions/io.js# d;
            s#^/homepath/.nvm/##;
            \#^versions$# d;
            s#^versions/##;
            s#^v#node-v#;
            s#^\(iojs\)[-/]v#\1.v#;
            s#^\(node\)[-/]v#\1.v#'
+++++ command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n
+++++ sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n
+++++ command sed '
            s/^\(iojs\)\./\1-/;
            s/^node\.//'
+++++ sed '
            s/^\(iojs\)\./\1-/;
            s/^node\.//'
++++ VERSIONS=
++++ '[' 1 -eq 1 ']'
++++ nvm_has unsetopt
++++ type unsetopt
++++ '[' false = true ']'
++++ '[' -z '' ']'
++++ echo N/A
++++ return 3
+++ VERSION=N/A
+++ '[' -z N/A ']'
+++ '[' _N/A = _N/A ']'
+++ echo N/A
+++ return 3
++ VERSION=N/A
$ echo $?
3
$

Hope this helps. If you don't want to look into it it's fine with me too.

@ljharb
Copy link
Member

ljharb commented Apr 16, 2016

I'd love to look into it - however, for me, it doesn't exit at all, because I've already tested it with set -e. What version of nvm are you running (nvm --version, and nvm debug while you're at it)?

I'm not sure why it's too much trouble to brew uninstall nvm and run the curl command in the README, and then you'll end up with software that's correctly installed.

Thanks for the trace! What happens if you wait to set -e until just before running nvm ls manually?

@Richie765
Copy link
Author

You're right, it's easy to setup. I just did it and the problem disappeared. Sorry to bother you with it!

@ljharb
Copy link
Member

ljharb commented Apr 17, 2016

np, thanks for confirming!

@ljharb ljharb closed this as completed Apr 17, 2016
@ljharb ljharb added non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. and removed needs followup We need some info or action from whoever filed this issue/PR. labels Apr 17, 2016
@tdm4
Copy link

tdm4 commented Jan 22, 2018

If nvm.sh does run successfully, why is it exiting with code 3 instead of 0?
Seems like it should be nvm.sh that should exit with the proper codes, that being, 0 = success, not 0 = failure

@fazeltab

This comment was marked as spam.

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 :-( non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. shell: bash/sh
Projects
None yet
Development

No branches or pull requests

4 participants