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

child_process: document the error when cwd does not exist #34505

Closed
wants to merge 2 commits into from
Closed

child_process: document the error when cwd does not exist #34505

wants to merge 2 commits into from

Conversation

FeelyChau
Copy link
Contributor

@FeelyChau FeelyChau commented Jul 24, 2020

If the option cwd does not exist, the error ENOENT is the same as the error emitted when the command does not exist, it's confusing.

Checklist

@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations. labels Jul 24, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.
@Trott
Copy link
Member

Trott commented Jul 28, 2020

Welcome @FeelyChau and thanks for the pull request. ENOENT means a path (whether file, directory, or other) does not exist. The additional information included with the error should make it clear whether the issue is the directory path or the command path. I'm not really sure this is a good thing to add to the docs. The errors should be self-explanatory. But let's see if others think differently. @nodejs/documentation @nodejs/child_process

@FeelyChau
Copy link
Contributor Author

@Trott Thanks for review.
Here is the code:

const ChildProcess = require('child_process');

const cp = ChildProcess.spawn('/usr/local/bin/node', [], { cwd: 'path_not_exists' });

cp.on('error', (err) => {
    console.log(err);
})

the output:

Error: spawn /usr/local/bin/node ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /usr/local/bin/node',
  path: '/usr/local/bin/node',
  spawnargs: []
}

The error is not specific.
I think the reason is libuv throw the ENOENT only, so we could not know the specific reasons.
Look at:

uv__write_int(error_fd, UV__ERR(errno));

@yorkie
Copy link
Contributor

yorkie commented Jul 28, 2020

I did address a bug related in mine until I found the call to chdir() at libuv. So IMO the other developers may not have an idea about considering it's an error caused by the cwd path. The cwd in options usually means it's an optional argument, and it wouldn't throw the same error from the required arguments which may be a little bit confusing :)

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this personally.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. review wanted PRs that need reviews. labels Nov 8, 2020
doc/api/child_process.md Outdated Show resolved Hide resolved
@aduh95 aduh95 added stalled Issues and PRs that are stalled. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Nov 11, 2020
@github-actions
Copy link
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. and removed stalled Issues and PRs that are stalled. commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 12, 2020
@aduh95
Copy link
Contributor

aduh95 commented Nov 14, 2020

Landed in bea9857

aduh95 pushed a commit that referenced this pull request Nov 14, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.

PR-URL: #34505
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@aduh95 aduh95 closed this Nov 14, 2020
codebytere pushed a commit that referenced this pull request Nov 22, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.

PR-URL: #34505
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@codebytere codebytere mentioned this pull request Nov 22, 2020
BethGriggs pushed a commit that referenced this pull request Dec 9, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.

PR-URL: #34505
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
BethGriggs pushed a commit that referenced this pull request Dec 10, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.

PR-URL: #34505
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@BethGriggs BethGriggs mentioned this pull request Dec 10, 2020
BethGriggs pushed a commit that referenced this pull request Dec 15, 2020
If the option cwd does not exist, the error ENOENT is the same as
the error emitted when the command does not exist, it's confusing.

PR-URL: #34505
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations. review wanted PRs that need reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants