child_process: better error reporting for exec

Report path to executable and argv on error, stderr is not enough in
many cases.

fix #6796
This commit is contained in:
Fedor Indutny 2014-01-05 01:50:54 +04:00
parent 4800310f6a
commit 730e511b35
2 changed files with 15 additions and 5 deletions

View File

@ -664,7 +664,7 @@ exports.execFile = function(file /* args, options, callback */) {
var exited = false;
var timeoutId;
var ex;
var ex = null;
function exithandler(code, signal) {
if (exited) return;
@ -689,16 +689,25 @@ exports.execFile = function(file /* args, options, callback */) {
}
if (ex) {
callback(ex, stdout, stderr);
// Will be handled later
} else if (code === 0 && signal === null) {
callback(null, stdout, stderr);
} else {
ex = new Error('Command failed: ' + stderr);
return;
}
var cmd = file;
if (args.length !== 0)
cmd += ' ' + args.join(' ');
if (!ex) {
ex = new Error('Command failed: ' + cmd + '\n' + stderr);
ex.killed = child.killed || killed;
ex.code = code < 0 ? uv.errname(code) : code;
ex.signal = signal;
callback(ex, stdout, stderr);
}
ex.cmd = cmd;
callback(ex, stdout, stderr);
}
function errorhandler(e) {

View File

@ -28,6 +28,7 @@ function test(fun, code) {
fun('does-not-exist', function(err) {
assert.equal(err.code, code);
assert(/does\-not\-exist/.test(err.cmd));
errors++;
});