From c88256b6d01d5a12ee0ebbc329223947a10b29f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 6 Oct 2017 21:06:18 -0700 Subject: [PATCH] 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] https://github.com/nodejs/node/pull/13601 --- lib/child_process.js | 3 +-- test/sequential/test-child-process-execsync.js | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index d9e11cb9a77830..a0bd01b16bde36 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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; } diff --git a/test/sequential/test-child-process-execsync.js b/test/sequential/test-child-process-execsync.js index 94810e890cd119..e190bad215987e 100644 --- a/test/sequential/test-child-process-execsync.js +++ b/test/sequential/test-child-process-execsync.js @@ -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; @@ -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); @@ -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; }); }