Skip to content

Commit

Permalink
child_process: restore exec{File}Sync error props
Browse files Browse the repository at this point in the history
In PR [1], a bunch of properties were removed from the error thrown by
execSync and execFileSync. It turns out that some of those were still
supposed to be there, as the documentation states that the error
contains the entire result from the spawnSync call.

[1] nodejs#13601
  • Loading branch information
targos committed Oct 21, 2017
1 parent 1395106 commit c88256b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ function checkExecSyncError(ret, args, cmd) {
err = new Error(msg);
}
if (err) {
err.status = ret.status < 0 ? errname(ret.status) : ret.status;
err.signal = ret.signal;
Object.assign(err, ret);
}
return err;
}
Expand Down
9 changes: 8 additions & 1 deletion test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
const common = require('../common');
const assert = require('assert');

const { execFileSync, execSync } = require('child_process');
const { execFileSync, execSync, spawnSync } = require('child_process');

const TIMER = 200;
const SLEEP = 2000;
Expand Down Expand Up @@ -112,6 +112,8 @@ assert.strictEqual(ret, `${msg}\n`);
// Verify the execFileSync() behavior when the child exits with a non-zero code.
{
const args = ['-e', 'process.exit(1)'];
const spawnSyncResult = spawnSync(process.execPath, args);
const spawnSyncKeys = Object.keys(spawnSyncResult);

assert.throws(() => {
execFileSync(process.execPath, args);
Expand All @@ -121,6 +123,11 @@ assert.strictEqual(ret, `${msg}\n`);
assert(err instanceof Error);
assert.strictEqual(err.message, msg);
assert.strictEqual(err.status, 1);
assert.strictEqual(typeof err.pid, 'number');
spawnSyncKeys.forEach((key) => {
if (key === 'pid') return;
assert.deepStrictEqual(err[key], spawnSyncResult[key]);
});
return true;
});
}

0 comments on commit c88256b

Please sign in to comment.