Skip to content

Commit 556ebab

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] #13601 PR-URL: #16060 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 801e61a commit 556ebab

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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: 16 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,16 @@ 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).sort();
117+
assert.deepStrictEqual(spawnSyncKeys, [
118+
'output',
119+
'pid',
120+
'signal',
121+
'status',
122+
'stderr',
123+
'stdout'
124+
]);
115125

116126
assert.throws(() => {
117127
execFileSync(process.execPath, args);
@@ -121,6 +131,11 @@ assert.strictEqual(ret, `${msg}\n`);
121131
assert(err instanceof Error);
122132
assert.strictEqual(err.message, msg);
123133
assert.strictEqual(err.status, 1);
134+
assert.strictEqual(typeof err.pid, 'number');
135+
spawnSyncKeys.forEach((key) => {
136+
if (key === 'pid') return;
137+
assert.deepStrictEqual(err[key], spawnSyncResult[key]);
138+
});
124139
return true;
125140
});
126141
}

0 commit comments

Comments
 (0)