Skip to content

Commit 0b43c08

Browse files
committed
util: pass on additional error() args
This fixes breakage introduced in 94b9948 when writing the max EventEmitter listeners warning to stderr. PR-URL: #4279 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 852313a commit 0b43c08

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/internal/util.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ exports.printDeprecationMessage = function(msg, warned) {
1818
};
1919

2020
exports.error = function(msg) {
21-
console.error(`${prefix}${msg}`);
21+
const fmt = `${prefix}${msg}`;
22+
if (arguments.length > 1) {
23+
const args = new Array(arguments.length);
24+
args[0] = fmt;
25+
for (let i = 1; i < arguments.length; ++i)
26+
args[i] = arguments[i];
27+
console.error.apply(console, args);
28+
} else {
29+
console.error(fmt);
30+
}
2231
};
2332

2433
exports.trace = function(msg) {

test/parallel/test-util-internal.js

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const common = require('../common');
55
const assert = require('assert');
66
const internalUtil = require('internal/util');
7+
const spawnSync = require('child_process').spawnSync;
78

89
function getHiddenValue(obj, name) {
910
return function() {
@@ -30,3 +31,12 @@ try {
3031
}
3132

3233
assert(/bad_syntax\.js:1/.test(arrowMessage));
34+
35+
const args = [
36+
'--expose-internals',
37+
'-e',
38+
"require('internal/util').error('foo %d', 5)"
39+
];
40+
const result = spawnSync(process.argv[0], args, { encoding: 'utf8' });
41+
assert.strictEqual(result.stderr.indexOf('%'), -1);
42+
assert(/foo 5/.test(result.stderr));

0 commit comments

Comments
 (0)