process: improve error message when cwd no longer exists#61736
Open
scott-memco wants to merge 1 commit intonodejs:mainfrom
Open
process: improve error message when cwd no longer exists#61736scott-memco wants to merge 1 commit intonodejs:mainfrom
scott-memco wants to merge 1 commit intonodejs:mainfrom
Conversation
When the current working directory is deleted or unmounted while a Node.js process is running, process.cwd() throws an error that references the internal libuv syscall (uv_cwd) rather than process.cwd(). This makes the error confusing to debug, especially when triggered deep in dependency code. Wrap the raw cwd() call in wrappedCwd() to catch ENOENT and throw a descriptive error that: - Explicitly mentions "current working directory does not exist" - Sets syscall to "process.cwd" instead of "uv_cwd" - Preserves the ENOENT error code for programmatic checks - Re-throws non-ENOENT errors unchanged Fixes: nodejs#57045 Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
|
Review requested:
|
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
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