mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-12-02 21:28:55 +03:00
[Fix] nvm_err, nvm_err_with_colors: do not fail when stderr is closed
Fixes #3906
This commit is contained in:
1 parent
aeace4606f
commit
ccb49e5cd0
3 files changed
+28
-2
No files matched your search
@@ -33,12 +33,15 @@ nvm_cd() {
|
||||
\cd "$@"
|
||||
}
|
||||
|
||||
# a caller that closed stderr, rather than redirecting it to /dev/null, makes
|
||||
# the `>&2` fail; zsh cannot report that, so it aborts the script, which only a
|
||||
# subshell contains, and `|| return 0` keeps the status from the caller
|
||||
nvm_err() {
|
||||
>&2 nvm_echo "$@"
|
||||
(>&2 nvm_echo "$@") || return 0
|
||||
}
|
||||
|
||||
nvm_err_with_colors() {
|
||||
>&2 nvm_echo_with_colors "$@"
|
||||
(>&2 nvm_echo_with_colors "$@") || return 0
|
||||
}
|
||||
|
||||
nvm_grep() {
|
||||
|
||||
@@ -54,4 +54,6 @@ EXPECTED_OUTPUT='Checksums matched!'
|
||||
[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"
|
||||
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"
|
||||
|
||||
(set +x; nvm_compare_checksum ../../../nvm.sh checksum 2>&-) || die "with stderr closed, expected to exit with code 0, got $?"
|
||||
|
||||
cleanup
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
\. ../../common.sh
|
||||
|
||||
try_err nvm_err 'an error'
|
||||
EXPECTED_OUTPUT='an error'
|
||||
[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"
|
||||
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"
|
||||
|
||||
try_err nvm_err_with_colors 'an error'
|
||||
EXPECTED_OUTPUT='an error'
|
||||
[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"
|
||||
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}"
|
||||
|
||||
nvm_err 'an error' 2>&- || die "nvm_err with stderr closed exited with code $?"
|
||||
nvm_err_with_colors 'an error' 2>&- || die "nvm_err_with_colors with stderr closed exited with code $?"
|
||||
Reference in new issue
Block a user