Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: restore exec{File}Sync error props #16060

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
targos committed Oct 21, 2017
commit c88256b6d01d5a12ee0ebbc329223947a10b29f6
3 changes: 1 addition & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logic being lost by moving to Object.assign()?

Copy link
Member Author

@targos targos Oct 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I don't think this logic should be there. It was also added in #13601.
The documentation says: "The Error object will contain the entire result from child_process.spawnSync()". If we want to translate the status, it should be done in spawnSync and execSync will inherit it.

err.signal = ret.signal;
Object.assign(err, ret);
}
return err;
}
9 changes: 8 additions & 1 deletion test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

const spawnSyncKeys = Object.keys(spawnSyncResult).sort();
assert.deepStrictEqual(spawnSyncKeys, [ /* ... */ ]);

Right now you check that the corresponding properties exist on the error object but that won't catch regressions where the result of spawnSync() lacks some (or all) properties.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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;
});
}