process: improve error message when cwd no longer exists #61736
+66
−2
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
When the current working directory is deleted or unmounted while a Node.js process is running,
process.cwd()throws:The error references
uv_cwd(a libuv internal) but never mentionsprocess.cwd()or explains that the directory was deleted. This is confusing to debug, especially when triggered deep in dependency code.Changes
lib/internal/bootstrap/switches/does_own_process_state.jsWraps the
rawMethods.cwd()call inwrappedCwd()to catchENOENTand throw a descriptive error:syscalltoprocess.cwdinstead ofuv_cwderr.code(ENOENT) so existing programmatic checks still workENOENTerrors unchangedBefore:
After:
test/parallel/test-process-cwd-enoent.js(new)Regression test that:
chdirs into it, deletes it, and callsprocess.cwd()code: 'ENOENT',syscall: 'process.cwd', and a message mentioning "current working directory"Fixes: #57045
Made with Cursor