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: Pass child in execFile resolve/reject too #34345

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

awwright
Copy link
Contributor

This PR adds a child property to the resolve & reject values to a promisify'd execFile & exec. This simplifies the ability to get at the ChildProcess instance when it's only necessary once the process has exited. (For example, to retrieve the process id).

As discussed in #34234.

Still needed are tests.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Jul 14, 2020
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
console.log('stdout:', stdout);
console.error('stderr:', stderr);
Copy link
Member

Choose a reason for hiding this comment

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

No unrelated changes, please. Can you back this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis I was trying to create several examples that show how to do the same thing with different functions, you'll see I used the same code in 326-335: https://github.com/nodejs/node/pull/34345/files#diff-fd8da87c3b5a1cec8e34fc76659ac6a0R326-R335 — is this change still too much, all considered?

Copy link
Contributor Author

@awwright awwright Jul 14, 2020

Choose a reason for hiding this comment

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

I changed it back, but there's another example that's already using the console.log('stdout:', stdout); form — is it more important to leave these unchanged, or can I touch them up for consistency?

Copy link
Member

Choose a reason for hiding this comment

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

If it's clearly related to the changes you're making anyway, then it's fine (but even then you should aim to make the most minimal change.) Apparently, it wasn't obvious to me yesterday that they were related. :-)

@@ -12,7 +12,9 @@ const execFile = promisify(child_process.execFile);

assert(promise.child instanceof child_process.ChildProcess);
promise.then(common.mustCall((obj) => {
assert.deepStrictEqual(obj, { stdout: '42\n', stderr: '' });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this is technically a breaking change — the test currently does not permit the addition of any properties. I changed this to multiple assertions, since (afaict) deepStrictEqual would be difficult to use on an instance of ChildProcess.

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM with a nit.

@@ -209,8 +209,7 @@ encoding, `Buffer` objects will be passed to the callback instead.
const { exec } = require('child_process');
exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
console.error(`exit(${error.code}): ${error}`);
Copy link
Member

Choose a reason for hiding this comment

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

Needs a return; but... it's still a mostly unrelated change. Can you back it out or move it to a separate commit?

@awwright
Copy link
Contributor Author

Idea: Would it make sense to add a code property too, to be symmetrical with the Error object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants