Skip to content

fix(process): improve error message for process.cwd() when directory is deleted#57184

Closed
Ankush1oo8 wants to merge 15 commits intonodejs:mainfrom
Ankush1oo8:fix-cwd-error-message
Closed

fix(process): improve error message for process.cwd() when directory is deleted#57184
Ankush1oo8 wants to merge 15 commits intonodejs:mainfrom
Ankush1oo8:fix-cwd-error-message

Conversation

@Ankush1oo8
Copy link

@Ankush1oo8 Ankush1oo8 commented Feb 23, 2025

This PR improves the error message thrown by process.cwd() when the current working directory is deleted. Instead of throwing a new error, it enhances the original error message, making it clearer that the directory was deleted while the process was still inside it.

Changes Made:

  • Modified wrappedCwd() to enhance the existing error message for ENOENT: uv_cwd instead of creating a new Error instance.
  • Ensured the error message explicitly states the reason and how to resolve it (using process.chdir() to switch directories).

Before (Old Behavior):

When the working directory was deleted, process.cwd() threw a generic error with little context:

Error: ENOENT: no such file or directory, uv_cwd

After (New Behavior):

Now, the error provides a more meaningful message:

Error: Current working directory does not exist - this can happen if the directory was deleted while the process was still inside it. Original error: ENOENT: no such file or directory, uv_cwd

Relevant Issue:

(If this PR fixes an issue, add the issue number here)
Example: Fixes #57045

PR-URL:

#57184

Reviewer Notes:

-added to docs

  • added test js file
  • Please review and let me know if further refinements are needed!

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process.cwd() fails in a not usefully descriptive way

7 participants