[Robustness] nvm_alias: explicitly succeed when the alias file is unreadable

The sed/awk pipeline exits with awk's status,
so an existing-but-unreadable alias file produces empty output with status 0 - but only by accident,
alongside sed's read error on stderr.
Make that contract explicit:
a nonzero status here would flip `nvm_ensure_default_set` from "default is already set" to recreating it,
silently overwriting a write-only default alias.
This commit is contained in:
Jordan Harband
2026-07-09 15:43:56 -07:00
parent 59cf9a4ef6
commit dd61ae4bc8
2 changed files with 46 additions and 0 deletions
+8
View File
@@ -1362,6 +1362,14 @@ nvm_alias() {
return 2
fi
if [ ! -r "${NVM_ALIAS_PATH}" ]; then
# an existing-but-unreadable alias file yields empty output with a success
# status - a nonzero status here would make `nvm_ensure_default_set`
# overwrite an existing default alias it merely could not read
nvm_err "Alias file is not readable: ${NVM_ALIAS_PATH}"
return 0
fi
command sed 's/#.*//; s/[[:space:]]*$//' "${NVM_ALIAS_PATH}" | command awk 'NF'
}