process: improve error message for process.cwd() when directory is deleted#57053
process: improve error message for process.cwd() when directory is deleted#57053Ankush1oo8 wants to merge 9 commits intonodejs:mainfrom Ankush1oo8:fix-cwd-error-message
Conversation
…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
|
Review requested:
|
|
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. |
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
|
|
what should further with this pr |
I agree that I believe originally there was a new error thrown without |
I think @jasnell has the best advice here--add the error as a |
|
Please check the pr |
|
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. |
I am sorry but i am not able to do it. |
…leted also keeping the old code intact
…leted with docs change
|
@addaleax can you check now please |
|
Now what should I do |
|
There's a merge conflict that needs to be resolved. Rebase your branch on the latest |
|
@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.
|
I there still some problem? |
|
No idea why that CI run didn't start. Trying again. |
|
@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.
const common = 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;
}
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const tmpDir = tmpdir.path;
const proc = 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) => {
const buf = Buffer.concat(chunks);
ok(/Current working directory does not exist/.test(buf.toString()));
}));
})); |
|
@jasnell Okey |
|
How do we that for all platforms |
|
Just add the test in |
|
Okey |
…leted added a test file to test/parallel
…/node into fix-cwd-error-message
|
@jasnell can you check now? |
|
@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? |
|
@jasnell Shall I delete this PR and again send one |
|
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: