fix: avoid glob expansion errors when no node versions installed#3741
Draft
tennisleng wants to merge 3 commits intonvm-sh:masterfrom
Draft
fix: avoid glob expansion errors when no node versions installed#3741tennisleng wants to merge 3 commits intonvm-sh:masterfrom
tennisleng wants to merge 3 commits intonvm-sh:masterfrom
Conversation
Member
|
Instead of altering a bunch of the logic, could we perhaps just disable nullglob when needed for the |
1a95084 to
da2a20f
Compare
…ions installed Fixes nvm-sh#3727 When no node versions are installed, nvm ls produces errors like: `find: /path/.nvm/versions/node/*: No such file or directory` This happens because bash expands `*` literally when nullglob is not set and the directory is empty. Solution: - For bash: temporarily enable nullglob before the find command - For other shells (sh, dash, zsh): suppress stderr (2>/dev/null) - Restore nullglob to its previous state after the command completes - Uses BASH_VERSION check to detect bash vs other shells
da2a20f to
9449392
Compare
Member
|
so this kind of works, but relies on nothing exiting prior to the restoration. i was thinking instead, of wrapping every call to |
Move nullglob enabling into the command substitution subshell so that the shell option change cannot persist to the parent shell, even if something exits early. This is a safer approach than save/restore. The subshell automatically cleans up when it exits, making it impossible for nullglob to leak into the user's shell environment.
Member
|
Awesome! Now we need a test that has the wrong nullglob setting and will prevent regressions :-) |
Adds a test that explicitly disables nullglob and runs nvm ls with an empty versions directory to ensure the fix prevents regressions. The test verifies: - nvm ls does not produce 'No such file or directory' errors - nvm ls exits with code 0 when no versions are installed
Author
done |
Author
|
@ljharb can you review this? |
ljharb
requested changes
Dec 29, 2025
Member
ljharb
left a comment
There was a problem hiding this comment.
Unfortunately the test passes even without the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3727
When no node versions are installed,
nvm lsproduces errors like:This happens because bash expands
*literally whennullglobis not set and the directory is empty.Solution
find DIR -mindepth 1 -maxdepth 1instead offind DIR/*Before
After
$ nvm ls -> systemTesting
~/.nvm/versions/node/directory