Skip to content

Commit

Permalink
child_process: remove extra newline in errors
Browse files Browse the repository at this point in the history
checkExecSyncError() creates error objects for execSync() and
execFileSync(). If the child process created stderr output, then
it is attached to the end of the error message. However, stderr
can be an empty Buffer object, which always passes the truthy
check, leading to an extra newline in the error message. This
commit adds a length check, which will work with both strings and
Buffers.

PR-URL: #9343
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig committed Nov 2, 2016
1 parent 0fb21df commit 49d1c36
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ function checkExecSyncError(ret) {
if (!err) {
var msg = 'Command failed: ';
msg += ret.cmd || ret.args.join(' ');
if (ret.stderr)
if (ret.stderr && ret.stderr.length > 0)
msg += '\n' + ret.stderr.toString();
err = new Error(msg);
}
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ assert.strictEqual(ret, msg + '\n',
const msg = `Command failed: ${process.execPath} ${args.join(' ')}`;

assert(err instanceof Error);
assert.strictEqual(err.message.trim(), msg);
assert.strictEqual(err.message, msg);
assert.strictEqual(err.status, 1);
return true;
});
Expand Down

0 comments on commit 49d1c36

Please sign in to comment.