Skip to content

fix: nvm_err and nvm_err_with_colors should not fail when stderr is closed - #3914

Closed
CJstate wants to merge 1 commit into
nvm-sh:masterfrom
CJstate:fix/nvm-err-closed-stderr
Closed

CJstate wants to merge 1 commit into
nvm-sh:masterfrom
CJstate:fix/nvm-err-closed-stderr

Conversation

@CJstate

@CJstate CJstate commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

When a caller closes stderr (instead of redirecting it to /dev/null) - for example Ruby's IO.popen(..., err: :close) or a child process that closes fd 2 explicitly - the >&2 redirection inside nvm_err returns non-zero. Because nvm_compare_checksum ends with nvm_err 'Checksums matched!' on success, a successful checksum is then reported as a failure and the install is aborted. zsh can additionally abort the whole shell when its own diagnostic about the failed redirection cannot be written.

Running the redirection in a subshell and discarding its exit code keeps that failure isolated from the caller. nvm_echo itself already silences printf errors via 2>/dev/null, so no further change is needed there.

The fix applies the same treatment to nvm_err_with_colors for consistency.

Fixes #3906

…losed

When a caller closes stderr (instead of redirecting it to /dev/null) -
for example Ruby's IO.popen(..., err: :close) - the >&2 redirection
inside nvm_err returns non-zero. nvm_compare_checksum ends with
nvm_err 'Checksums matched!' on success, so a successful checksum was
reported as a failure and the install was aborted. zsh can also abort
the whole shell when its diagnostic about the failed redirection
cannot be written.

Run the redirection in a subshell and discard its exit code, while
keeping nvm_echo's existing stderr silencing for printf failures.

Fixes #3906

@schnare22 schnare22 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I owe you send me a link I'll take care of you I got only couple hundred more to fix miscellaneous

Comment thread nvm.sh

This comment was marked as spam.

@ljharb

ljharb commented Sep 4, 2026

Copy link
Copy Markdown
Member

Duplicate of #3907.

@ljharb ljharb closed this Sep 4, 2026
schnare22

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvm_err fails when stderr is closed

4 participants