Repository: nvm-sh/nvm
File: nvm.sh (Shell)

Code before:
        return 5
      fi

      local FLAVOR
      if nvm_is_iojs_version "$VERSION"; then
        FLAVOR="$(nvm_iojs_prefix)"
      else
        FLAVOR="$(nvm_node_prefix)"
      fi

      if nvm_is_version_installed "$VERSION" && nvm use "$VERSION"; then
        nvm_err "$VERSION is already installed."
        if [ -z "$SKIP_DEFAULT_PACKAGES" ] && [ -n "$DEFAULT_PACKAGES" ]; then
          nvm_install_default_packages "$DEFAULT_PACKAGES"
        fi
        if [ -n "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
          nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
        fi
        if [ -n "${LTS-}" ]; then
          nvm_ensure_default_set "lts/${LTS}"
        else
          nvm_ensure_default_set "$provided_version"
        fi
        return $?
      fi

      local EXIT_CODE
      EXIT_CODE=-1
      if [ -n "${NVM_INSTALL_THIRD_PARTY_HOOK-}" ]; then
        nvm_err '** $NVM_INSTALL_THIRD_PARTY_HOOK env var set; dispatching to third-party installation method **'
        local NVM_METHOD_PREFERENCE
        NVM_METHOD_PREFERENCE='binary'
        if [ $nobinary -eq 1 ]; then
          NVM_METHOD_PREFERENCE='source'
        fi
        local VERSION_PATH
        VERSION_PATH="$(nvm_version_path "${VERSION}")"
        "${NVM_INSTALL_THIRD_PARTY_HOOK}" "${VERSION}" "${FLAVOR}" std "${NVM_METHOD_PREFERENCE}" "${VERSION_PATH}" || {
          EXIT_CODE=$?
          nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var failed to install! ***'
          return $EXIT_CODE
        }
        if ! nvm_is_version_installed "${VERSION}"; then
          nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var claimed to succeed, but failed to install! ***'
          return 33
        fi
        EXIT_CODE=0
      else

        if [ "_$NVM_OS" = "_freebsd" ]; then
          # node.js and io.js do not have a FreeBSD binary

Review comment (bug):
it's very intentional that the error message prints only if `nvm_is_version_installed` fails, and not if `nvm use` fails.

Code after:
              nvm_err "Only one package per line is allowed in the ${NVM_DIR}/default-packages file. Please remove any lines with multiple space-seperated values."
              return 1
            ;;
          esac

          DEFAULT_PACKAGES="${DEFAULT_PACKAGES}${line} "
        done < "${NVM_DIR}/default-packages"
      fi

      if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ] && [ "$(nvm_ensure_version_prefix "${PROVIDED_REINSTALL_PACKAGES_FROM}")" = "${VERSION}" ]; then
        nvm_err "You can't reinstall global packages from the same version of node you're installing."
        return 4
      elif [ "${REINSTALL_PACKAGES_FROM-}" = 'N/A' ]; then
        nvm_err "If --reinstall-packages-from is provided, it must point to an installed version of node."
        return 5
      fi

      local FLAVOR
      if nvm_is_iojs_version "$VERSION"; then
        FLAVOR="$(nvm_iojs_prefix)"
      else
        FLAVOR="$(nvm_node_prefix)"
      fi

      if nvm_is_version_installed "$VERSION"; then
        nvm_err "$VERSION is already installed."
        if nvm use "$VERSION"; then
          if [ -z "${SKIP_DEFAULT_PACKAGES-}" ] && [ -n "${DEFAULT_PACKAGES-}" ]; then
            nvm_install_default_packages "$DEFAULT_PACKAGES"
          fi
          if [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
            nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
          fi
        fi
        if [ -n "${LTS-}" ]; then
          nvm_ensure_default_set "lts/${LTS}"
        else
          nvm_ensure_default_set "$provided_version"
        fi
        return $?
      fi

      local EXIT_CODE
      EXIT_CODE=-1
      if [ -n "${NVM_INSTALL_THIRD_PARTY_HOOK-}" ]; then
        nvm_err '** $NVM_INSTALL_THIRD_PARTY_HOOK env var set; dispatching to third-party installation method **'
        local NVM_METHOD_PREFERENCE
        NVM_METHOD_PREFERENCE='binary'
        if [ $nobinary -eq 1 ]; then
          NVM_METHOD_PREFERENCE='source'
        fi