Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

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!

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Feb 23, 2025
@Ankush1oo8
Copy link
Author

@jasnell can you check this i have done some thing that caused deletion of repo can you now check the pr

@Ankush1oo8 Ankush1oo8 changed the title process: improve error message for process.cwd() when directory is de… process: improve error message for process.cwd() when directory is deleted Feb 23, 2025
@Ankush1oo8
Copy link
Author

Are there more changes to make

@Ankush1oo8
Copy link
Author

@aduh95 can you check for further process to approve

@aduh95
Copy link
Contributor

aduh95 commented Feb 25, 2025

Any reason you're not taking any of my suggestions? It's certainly fine if you disagree with those, but please at least comment on each explaining why

@Ankush1oo8
Copy link
Author

Ohh sorry I think I made the changes but did not commit

@Ankush1oo8
Copy link
Author

@aduh95 i have made changes according to your suggesations

@Ankush1oo8 Ankush1oo8 changed the title process: improve error message for process.cwd() when directory is deleted fix(process): improve error message for process.cwd() when directory is deleted Feb 25, 2025
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.31%. Comparing base (9fd90d9) to head (91d4c41).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57184   +/-   ##
=======================================
  Coverage   90.31%   90.31%           
=======================================
  Files         630      630           
  Lines      184513   184540   +27     
  Branches    36080    36077    -3     
=======================================
+ Hits       166643   166671   +28     
- Misses      10955    10967   +12     
+ Partials     6915     6902   -13     
Files with missing lines Coverage Δ
src/node_errors.h 85.29% <ø> (ø)
src/node_process_methods.cc 85.60% <100.00%> (-0.40%) ⬇️

... and 32 files with indirect coverage changes

@Ankush1oo8
Copy link
Author

can anyone tell me what should i do now

@addaleax
Copy link
Member

@Ankush1oo8 As you can see, GH does point at failures in another test that are definitely related to this change – the exit code is now different in at least one case (test/parallel/test-cwd-enoent-preload.js). You'll need to debug why that particular problem occurs – it's probably a regression of the fix that originally introduced that test file, 2d251e6.

@addaleax addaleax added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 26, 2025
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
4 participants