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:
parent
4800310f6a
commit
730e511b35
@ -664,7 +664,7 @@ exports.execFile = function(file /* args, options, callback */) {
|
|||||||
var exited = false;
|
var exited = false;
|
||||||
var timeoutId;
|
var timeoutId;
|
||||||
|
|
||||||
var ex;
|
var ex = null;
|
||||||
|
|
||||||
function exithandler(code, signal) {
|
function exithandler(code, signal) {
|
||||||
if (exited) return;
|
if (exited) return;
|
||||||
@ -689,16 +689,25 @@ exports.execFile = function(file /* args, options, callback */) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ex) {
|
if (ex) {
|
||||||
callback(ex, stdout, stderr);
|
// Will be handled later
|
||||||
} else if (code === 0 && signal === null) {
|
} else if (code === 0 && signal === null) {
|
||||||
callback(null, stdout, stderr);
|
callback(null, stdout, stderr);
|
||||||
} else {
|
return;
|
||||||
ex = new Error('Command failed: ' + stderr);
|
}
|
||||||
|
|
||||||
|
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.killed = child.killed || killed;
|
||||||
ex.code = code < 0 ? uv.errname(code) : code;
|
ex.code = code < 0 ? uv.errname(code) : code;
|
||||||
ex.signal = signal;
|
ex.signal = signal;
|
||||||
callback(ex, stdout, stderr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ex.cmd = cmd;
|
||||||
|
callback(ex, stdout, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorhandler(e) {
|
function errorhandler(e) {
|
||||||
|
@ -28,6 +28,7 @@ function test(fun, code) {
|
|||||||
|
|
||||||
fun('does-not-exist', function(err) {
|
fun('does-not-exist', function(err) {
|
||||||
assert.equal(err.code, code);
|
assert.equal(err.code, code);
|
||||||
|
assert(/does\-not\-exist/.test(err.cmd));
|
||||||
errors++;
|
errors++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user