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

util.promisify custom implementation of child_process.exec throws away stdout and stderr in case of error #13364

Closed
giltayar opened this issue Jun 1, 2017 · 1 comment
Labels
child_process Issues and PRs related to the child_process subsystem. promises Issues and PRs related to ECMAScript promises. util Issues and PRs related to the built-in util module.

Comments

@giltayar
Copy link
Contributor

giltayar commented Jun 1, 2017

  • Version: v8.0.0
  • Platform: MacOS
  • Subsystem: child_process

Wrapping child_process.exec-s in util.promisify returns a function that returns stdout and stderr in case there is no error (which is good), but does not return stdout and stderr in case of an error.

This means that if the command fails (with exit code != 0) then we have no access to the stdout and stderr (well, we can access stderr in a hackish way through exc.toString(), but that's hackish and still stdout can't be reached).

I suggest attaching stdout and stderr properties to the error returned by the rejected promise. If this is OK with everybody, I can fix it and create a pull request for this.

@addaleax addaleax added child_process Issues and PRs related to the child_process subsystem. promises Issues and PRs related to ECMAScript promises. util Issues and PRs related to the built-in util module. labels Jun 1, 2017
@addaleax
Copy link
Member

addaleax commented Jun 1, 2017

I suggest attaching stdout and stderr properties to the error returned by the rejected promise. If this is OK with everybody, I can fix it and create a pull request for this.

That sounds reasonable to me, yup.

addaleax pushed a commit that referenced this issue Jun 10, 2017
This converts the initial implementation of a promised exec that used
the customPromisifyArgs support in util.promisify with a custom
implementation. This is because exec and execFile, when there is an
error, still supply the stdout and stderr of the process, and yet
the promisified version with customPromisifyArgs does
not supply this ability.

I created a custom implementation and attached it to exec and execFile
using the util.promisify.custom key.

Fixes: #13364
PR-URL: #13388
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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. promises Issues and PRs related to ECMAScript promises. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

2 participants