child_process: promisify includes stdio in error · nodejs/node@d66d4fc
@@ -22,9 +22,9 @@
2222'use strict';
23232424const util = require('util');
25-const {
26- deprecate, convertToValidSignal, customPromisifyArgs
27-} = require('internal/util');
25+const { deprecate, convertToValidSignal } = require('internal/util');
26+const { createPromise,
27+ promiseResolve, promiseReject } = process.binding('util');
2828const debug = util.debuglog('child_process');
29293030const uv = process.binding('uv');
@@ -140,9 +140,27 @@ exports.exec = function(command /*, options, callback*/) {
140140opts.callback);
141141};
142142143-Object.defineProperty(exports.exec, customPromisifyArgs,
144-{ value: ['stdout', 'stderr'], enumerable: false });
143+const customPromiseExecFunction = (orig) => {
144+return (...args) => {
145+const promise = createPromise();
145146147+orig(...args, (err, stdout, stderr) => {
148+if (err !== null) {
149+err.stdout = stdout;
150+err.stderr = stderr;
151+promiseReject(promise, err);
152+} else {
153+promiseResolve(promise, { stdout, stderr });
154+}
155+});
156+return promise;
157+};
158+};
159+160+Object.defineProperty(exports.exec, util.promisify.custom, {
161+enumerable: false,
162+value: customPromiseExecFunction(exports.exec)
163+});
146164147165exports.execFile = function(file /*, args, options, callback*/) {
148166var args = [];
@@ -338,8 +356,10 @@ exports.execFile = function(file /*, args, options, callback*/) {
338356return child;
339357};
340358341-Object.defineProperty(exports.execFile, customPromisifyArgs,
342-{ value: ['stdout', 'stderr'], enumerable: false });
359+Object.defineProperty(exports.execFile, util.promisify.custom, {
360+enumerable: false,
361+value: customPromiseExecFunction(exports.execFile)
362+});
343363344364const _deprecatedCustomFds = deprecate(
345365function deprecateCustomFds(options) {