Skip to content
Myr

[Fix] `nvm_ls_remote_combined`: propagate iojs remote listing failures

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`return $A || $B` only evaluates the first argument, since `return` always succeeds. The io.js exit code was never checked, silently swallowing remote listing failures. Bug introduced in https://github.com/nvm-sh/nvm/commit/ea127846290b1126556e256031383d171a4e38d8 / #616.

authored by Jordan Harband · committed by Jordan Harband · parent 6f428a1 · Browse files · 2 files+72 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+72 added−1 removed

  • tests:+68 added−0 removed
  • other:+4 added−1 removed

2 files+72 added−1 removed

added:test/fast/Unit tests/nvm_remote_versions propagates iojs failure+68 added
1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }45cleanup() {6 unset -f nvm_ls_remote nvm_ls_remote_iojs7}89\. ../../../nvm.sh1011\. ../../common.sh1213# When nvm_ls_remote succeeds but nvm_ls_remote_iojs fails,14# nvm_remote_versions should propagate the iojs failure exit code.15nvm_ls_remote() {16 echo "v0.10.0"17 return 018}19nvm_ls_remote_iojs() {20 echo "N/A"21 return 522}2324try nvm_remote_versions25[ "_$CAPTURED_EXIT_CODE" = "_5" ] || die "expected iojs failure exit code 5 to propagate, got $CAPTURED_EXIT_CODE"2627# When nvm_ls_remote fails and nvm_ls_remote_iojs succeeds,28# nvm_remote_versions should propagate the node failure exit code.29nvm_ls_remote() {30 echo "v0.10.0"31 return 732}33nvm_ls_remote_iojs() {34 echo "iojs-v1.0.0"35 return 036}3738try nvm_remote_versions39[ "_$CAPTURED_EXIT_CODE" = "_7" ] || die "expected node failure exit code 7 to propagate, got $CAPTURED_EXIT_CODE"4041# When both fail, nvm_remote_versions should propagate the node failure exit code42# (since it is checked first).43nvm_ls_remote() {44 echo "v0.10.0"45 return 346}47nvm_ls_remote_iojs() {48 echo "iojs-v1.0.0"49 return 450}5152try nvm_remote_versions53[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "expected node failure exit code 3 to take priority, got $CAPTURED_EXIT_CODE"5455# When both succeed, exit code should be 0.56nvm_ls_remote() {57 echo "v0.10.0"58 return 059}60nvm_ls_remote_iojs() {61 echo "iojs-v1.0.0"62 return 063}6465try nvm_remote_versions66[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "expected exit code 0 when both succeed, got $CAPTURED_EXIT_CODE"6768cleanup
modified:nvm.sh+4 added-1 removed
876 unmodified lines
877 fi878 # the `sed` is to remove trailing whitespaces (see "weird behavior" ~25 lines up)879 nvm_echo "${VERSIONS}" | command sed 's/ *$//g'880 # shellcheck disable=SC2317881 return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE881 if [ "${NVM_LS_REMOTE_EXIT_CODE}" != '0' ]; then882 return "${NVM_LS_REMOTE_EXIT_CODE}"883 fi884 return "${NVM_LS_REMOTE_IOJS_EXIT_CODE}"885}886887nvm_is_valid_version() {888 if nvm_validate_implicit_alias "${1-}" 2>/dev/null; then
3929 unmodified lines