mirror of https://github.com/nodejs/node.git
child_process: add debug and error details
This commit adds debug() calls to spawn() and spawnSync(), and attaches additional information to Error objects. Fixes: https://github.com/iojs/io.js/issues/720 PR-URL: https://github.com/iojs/io.js/pull/721 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>pull/665/merge
parent
6f7a9784ea
commit
9a8f18613d
|
@ -6,6 +6,7 @@ const net = require('net');
|
|||
const dgram = require('dgram');
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
const debug = util.debuglog('child_process');
|
||||
|
||||
const Process = process.binding('process_wrap').Process;
|
||||
const WriteWrap = process.binding('stream_wrap').WriteWrap;
|
||||
|
@ -958,6 +959,8 @@ var spawn = exports.spawn = function(/*file, args, options*/) {
|
|||
var options = opts.options;
|
||||
var child = new ChildProcess();
|
||||
|
||||
debug('spawn', opts.args, options);
|
||||
|
||||
child.spawn({
|
||||
file: opts.file,
|
||||
args: opts.args,
|
||||
|
@ -1035,6 +1038,7 @@ function ChildProcess() {
|
|||
if (self.spawnfile)
|
||||
err.path = self.spawnfile;
|
||||
|
||||
err.spawnargs = self.spawnargs.slice(1);
|
||||
self.emit('error', err);
|
||||
} else {
|
||||
self.emit('exit', self.exitCode, self.signalCode);
|
||||
|
@ -1097,6 +1101,7 @@ ChildProcess.prototype.spawn = function(options) {
|
|||
}
|
||||
|
||||
this.spawnfile = options.file;
|
||||
this.spawnargs = options.args;
|
||||
|
||||
var err = this._handle.spawn(options);
|
||||
|
||||
|
@ -1242,6 +1247,8 @@ function spawnSync(/*file, args, options*/) {
|
|||
|
||||
var i;
|
||||
|
||||
debug('spawnSync', opts.args, options);
|
||||
|
||||
options.file = opts.file;
|
||||
options.args = opts.args;
|
||||
options.envPairs = opts.envPairs;
|
||||
|
@ -1289,8 +1296,11 @@ function spawnSync(/*file, args, options*/) {
|
|||
result.stdout = result.output && result.output[1];
|
||||
result.stderr = result.output && result.output[2];
|
||||
|
||||
if (result.error)
|
||||
result.error = errnoException(result.error, 'spawnSync');
|
||||
if (result.error) {
|
||||
result.error = errnoException(result.error, 'spawnSync ' + opts.file);
|
||||
result.error.path = opts.file;
|
||||
result.error.spawnargs = opts.args.slice(1);
|
||||
}
|
||||
|
||||
util._extend(result, opts);
|
||||
|
||||
|
|
Loading…
Reference in New Issue