Skip to content

Commit 9a8f186

Browse files
remixzcjihrig
authored andcommitted
child_process: add debug and error details
This commit adds debug() calls to spawn() and spawnSync(), and attaches additional information to Error objects. Fixes: #720 PR-URL: #721 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 6f7a978 commit 9a8f186

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/child_process.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const net = require('net');
66
const dgram = require('dgram');
77
const assert = require('assert');
88
const util = require('util');
9+
const debug = util.debuglog('child_process');
910

1011
const Process = process.binding('process_wrap').Process;
1112
const WriteWrap = process.binding('stream_wrap').WriteWrap;
@@ -958,6 +959,8 @@ var spawn = exports.spawn = function(/*file, args, options*/) {
958959
var options = opts.options;
959960
var child = new ChildProcess();
960961

962+
debug('spawn', opts.args, options);
963+
961964
child.spawn({
962965
file: opts.file,
963966
args: opts.args,
@@ -1035,6 +1038,7 @@ function ChildProcess() {
10351038
if (self.spawnfile)
10361039
err.path = self.spawnfile;
10371040

1041+
err.spawnargs = self.spawnargs.slice(1);
10381042
self.emit('error', err);
10391043
} else {
10401044
self.emit('exit', self.exitCode, self.signalCode);
@@ -1097,6 +1101,7 @@ ChildProcess.prototype.spawn = function(options) {
10971101
}
10981102

10991103
this.spawnfile = options.file;
1104+
this.spawnargs = options.args;
11001105

11011106
var err = this._handle.spawn(options);
11021107

@@ -1242,6 +1247,8 @@ function spawnSync(/*file, args, options*/) {
12421247

12431248
var i;
12441249

1250+
debug('spawnSync', opts.args, options);
1251+
12451252
options.file = opts.file;
12461253
options.args = opts.args;
12471254
options.envPairs = opts.envPairs;
@@ -1289,8 +1296,11 @@ function spawnSync(/*file, args, options*/) {
12891296
result.stdout = result.output && result.output[1];
12901297
result.stderr = result.output && result.output[2];
12911298

1292-
if (result.error)
1293-
result.error = errnoException(result.error, 'spawnSync');
1299+
if (result.error) {
1300+
result.error = errnoException(result.error, 'spawnSync ' + opts.file);
1301+
result.error.path = opts.file;
1302+
result.error.spawnargs = opts.args.slice(1);
1303+
}
12941304

12951305
util._extend(result, opts);
12961306

0 commit comments

Comments
 (0)