Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.4k
process: improve error message for process.cwd() when directory is deleted#57053
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
Ankush1oo8 commented Feb 14, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
…leted If the current working directory is deleted, process.cwd() throws a generic 'uv_cwd' error, which can be confusing. This commit enhances the error message by modifying the original error instead of throwing a new one. PR-URL: #57053
nodejs-github-bot commented Feb 14, 2025
Review requested:
|
Qard commented Feb 16, 2025
Thanks for taking this one on! ❤️ A few things though: Why would mutating the error be preferable to using Line 75 in d384151
error.cause would preserve it, which may be helpful.This also needs a test. I think the change to the native function may make the javascript change unreachable due to no longer having the syscall info. 🤔 And lastly, a more minor detail: a couple lint checks fail as the commit message is too long and the message lines are too long. We limit lines to 80 columns. |
codecovbot commented Feb 16, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #57053 +/- ## ======================================= Coverage 89.10% 89.11% ======================================= Files 665 665 Lines 193203 193213 +10 Branches 37216 37216 ======================================= + Hits 172158 172181 +23 - Misses 13768 13778 +10 + Partials 7277 7254 -23
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Ankush1oo8 commented Feb 18, 2025
what should further with this pr |
gurgunday commented Feb 19, 2025
I agree that I believe originally there was a new error thrown without |
Qard commented Feb 20, 2025
I think @jasnell has the best advice here--add the error as a |
Ankush1oo8 commented Feb 20, 2025
Please check the pr |
jasnell commented Feb 21, 2025
Code change LGTM but this needs a test. The test might be a bit tricky but it could create a temporary directory with a script in it, run that script, delete that directory, then call the api from the script that was in that directory, etc.... anyway, once a test is added I'm happy to approve this. |
Ankush1oo8 commented Feb 21, 2025
I am sorry but i am not able to do it. |
Uh oh!
There was an error while loading. Please reload this page.
…leted also keeping the old code intact
Uh oh!
There was an error while loading. Please reload this page.
…leted with docs change
Ankush1oo8 commented Feb 21, 2025
@addaleax can you check now please |
nodejs-github-bot commented Feb 21, 2025
Ankush1oo8 commented Feb 22, 2025
Now what should I do |
jasnell commented Feb 22, 2025
There's a merge conflict that needs to be resolved. Rebase your branch on the latest |
Ankush1oo8 commented Feb 23, 2025
@jasnell I have done the merging of conflicts can you tell if something more to be done |
This comment was marked as outdated.
This comment was marked as outdated.
Ankush1oo8 commented Feb 23, 2025
I there still some problem? |
nodejs-github-bot commented Feb 23, 2025
jasnell commented Feb 23, 2025
No idea why that CI run didn't start. Trying again. |
jasnell commented Feb 23, 2025
@Ankush1oo8 ... here's a possible test that works locally for me. We'll need to verify that it works on all platforms. 'use strict';// This test verifies that an appropriate error is thrown when the current// working directory is deleted and process.cwd() is called.//// We do this by spawning a forked process and deleting the tmp cwd// while it is starting up.constcommon=require('../common');const{ fork }=require('node:child_process');const{ rmSync }=require('node:fs');const{ strictEqual, ok }=require('node:assert');const{ Buffer }=require('node:buffer');if(process.argv[2]==='child'){return;}consttmpdir=require('../common/tmpdir');tmpdir.refresh();consttmpDir=tmpdir.path;constproc=fork(__filename,['child'],{cwd: tmpDir,silent: true,});proc.on('spawn',common.mustCall(()=>rmSync(tmpDir,{recursive: true})));proc.on('exit',common.mustCall((code)=>{strictEqual(code,1);proc.stderr.toArray().then(common.mustCall((chunks)=>{constbuf=Buffer.concat(chunks);ok(/Currentworkingdirectorydoesnotexist/.test(buf.toString()));}));})); |
Ankush1oo8 commented Feb 23, 2025
@jasnell Okey |
Ankush1oo8 commented Feb 23, 2025
How do we that for all platforms |
jasnell commented Feb 23, 2025
Just add the test in |
Ankush1oo8 commented Feb 23, 2025
Okey |
…leted added a test file to test/parallel
…/node into fix-cwd-error-message
Ankush1oo8 commented Feb 23, 2025
@jasnell can you check now? |
jasnell commented Feb 23, 2025
@Ankush1oo8 ... unfortunately it looks like you used a merge commit to catch this up to main. We don't do merge commits. Can I ask you to remove the merge commit and use rebase to catch it up? |
Ankush1oo8 commented Feb 23, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@jasnell Shall I delete this PR and again send one |
jasnell commented Feb 23, 2025
No need. You ought to be able to reset your local branch to just your commits to drop the merge commit. |
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:
wrappedCwd()to enhance the existing error message forENOENT: uv_cwdinstead of creating a newErrorinstance.process.chdir()to switch directories).Before (Old Behavior):
When the working directory was deleted,
process.cwd()threw a generic error with little context:After (New Behavior):
Now, the error provides a more meaningful message:
Relevant Issue:
(If this PR fixes an issue, add the issue number here)
Example: Fixes #XXXX
PR-URL:
#57053
Reviewer Notes: