Skip to content

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

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

Open
wants to merge 15 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.15%. Comparing base (4acb854) to head (bf901af).
Report is 96 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57184   +/-   ##
=======================================
  Coverage   90.15%   90.15%           
=======================================
  Files         630      630           
  Lines      186756   186759    +3     
  Branches    36648    36651    +3     
=======================================
+ Hits       168362   168370    +8     
- Misses      11193    11201    +8     
+ Partials     7201     7188   -13     
Files with missing lines Coverage Δ
src/node_errors.h 87.50% <ø> (ø)
src/node_process_methods.cc 87.50% <100.00%> (-0.36%) ⬇️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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
@Ankush1oo8
Copy link
Author

@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.

Can you check now

@Ankush1oo8
Copy link
Author

@addaleax I don't know what to doi have tried to solve it but did not get any clue

@Ankush1oo8
Copy link
Author

i have tried to change the code in test-cwd-enoent-preload.js
I think this can solve the cli test

@Ankush1oo8 Ankush1oo8 requested review from aduh95 and addaleax March 11, 2025 08:30
@aduh95
Copy link
Contributor

aduh95 commented Mar 11, 2025

There are lint errors to address

@Ankush1oo8
Copy link
Author

Ankush1oo8 commented Mar 11, 2025

what should i do about first commit message @aduh95 can help please

@pmarchini
Copy link
Member

Hey @Ankush1oo8, please rewrite your commit history so that it includes only one commit that passes the validations provided here: https://github.com/nodejs/core-validate-commit

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
5 participants