Skip to content

Commit e771432

Browse files
cjihrigitaloacasas
authored andcommitted
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: nodejs#9343 Reviewed-By: Wyatt Preul <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent aa6b9f9 commit e771432

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
@@ -485,7 +485,7 @@ function checkExecSyncError(ret) {
485485
if (!err) {
486486
var msg = 'Command failed: ';
487487
msg += ret.cmd || ret.args.join(' ');
488-
if (ret.stderr)
488+
if (ret.stderr && ret.stderr.length > 0)
489489
msg += '\n' + ret.stderr.toString();
490490
err = new Error(msg);
491491
}

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)