Skip to content

Commit c88256b

Browse files
committed
child_process: restore exec{File}Sync error props
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
1 parent 1395106 commit c88256b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/child_process.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ function checkExecSyncError(ret, args, cmd) {
574574
err = new Error(msg);
575575
}
576576
if (err) {
577-
err.status = ret.status < 0 ? errname(ret.status) : ret.status;
578-
err.signal = ret.signal;
577+
Object.assign(err, ret);
579578
}
580579
return err;
581580
}

test/sequential/test-child-process-execsync.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525

26-
const { execFileSync, execSync } = require('child_process');
26+
const { execFileSync, execSync, spawnSync } = require('child_process');
2727

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

116118
assert.throws(() => {
117119
execFileSync(process.execPath, args);
@@ -121,6 +123,11 @@ assert.strictEqual(ret, `${msg}\n`);
121123
assert(err instanceof Error);
122124
assert.strictEqual(err.message, msg);
123125
assert.strictEqual(err.status, 1);
126+
assert.strictEqual(typeof err.pid, 'number');
127+
spawnSyncKeys.forEach((key) => {
128+
if (key === 'pid') return;
129+
assert.deepStrictEqual(err[key], spawnSyncResult[key]);
130+
});
124131
return true;
125132
});
126133
}

0 commit comments

Comments
 (0)