-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
Ankush1oo8
wants to merge
15
commits into
nodejs:main
Choose a base branch
from
Ankush1oo8:fix-cwd-error-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8987833
process: improve error message for process.cwd() when directory is de…
Ankush1oo8 881263b
Merge branch 'nodejs:main' into fix-cwd-error-message
Ankush1oo8 05bcd10
Update doc/api/errors.md
Ankush1oo8 b43c4c4
Update doc/api/errors.md
Ankush1oo8 e23e544
Update test/parallel/test-process-cwd-deleted.js
Ankush1oo8 c29b27a
Update test-process-cwd-deleted.js
Ankush1oo8 a8453e6
Update test-process-cwd-deleted.js
Ankush1oo8 91d4c41
Update test-process-cwd-deleted.js
Ankush1oo8 c7ed580
Update test-process-cwd-deleted.js
Ankush1oo8 929f6bb
Merge branch 'nodejs:main' into fix-cwd-error-message
Ankush1oo8 09c36b1
Update test-cwd-enoent-preload.js
Ankush1oo8 3e9ebc1
Merge branch 'nodejs:main' into fix-cwd-error-message
Ankush1oo8 c0dc91e
fix: remove unused Buffer variable in test-process-cwd-deleted.js
Ankush1oo8 c584dcf
Merge branch 'nodejs:main' into fix-cwd-error-message
Ankush1oo8 bf901af
Merge branch 'nodejs:main' into fix-cwd-error-message
Ankush1oo8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'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 assert = require('node:assert'); // Import assert properly | ||
const { Buffer } = require('node:buffer'); | ||
|
||
if (process.argv[2] === 'child') { | ||
try { | ||
while (true) { | ||
process.cwd(); // Continuously call process.cwd() | ||
Ankush1oo8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); // Ensure the process exits with failure | ||
} | ||
Ankush1oo8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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) => { | ||
assert.strictEqual(code, 1); | ||
proc.stderr.toArray().then(common.mustCall((chunks) => { | ||
const buf = Buffer.concat(chunks); | ||
assert.match(buf.toString(), /Current working directory does not exist/); | ||
})); | ||
})); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.