Skip to content

Commit 49d1c36

Browse files
committed
child_process: remove extra newline in errors
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0fb21df commit 49d1c36

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/child_process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ function checkExecSyncError(ret) {
483483
if (!err) {
484484
var msg = 'Command failed: ';
485485
msg += ret.cmd || ret.args.join(' ');
486-
if (ret.stderr)
486+
if (ret.stderr && ret.stderr.length > 0)
487487
msg += '\n' + ret.stderr.toString();
488488
err = new Error(msg);
489489
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ assert.strictEqual(ret, msg + '\n',
9898
const msg = `Command failed: ${process.execPath} ${args.join(' ')}`;
9999

100100
assert(err instanceof Error);
101-
assert.strictEqual(err.message.trim(), msg);
101+
assert.strictEqual(err.message, msg);
102102
assert.strictEqual(err.status, 1);
103103
return true;
104104
});

0 commit comments

Comments
 (0)