Skip to content

Commit

Permalink
util: pass on additional error() args
Browse files Browse the repository at this point in the history
This fixes breakage introduced in 94b9948 when writing the max
EventEmitter listeners warning to stderr.

PR-URL: #4279
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
mscdex committed Dec 17, 2015
1 parent 852313a commit 0b43c08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ exports.printDeprecationMessage = function(msg, warned) {
};

exports.error = function(msg) {
console.error(`${prefix}${msg}`);
const fmt = `${prefix}${msg}`;
if (arguments.length > 1) {
const args = new Array(arguments.length);
args[0] = fmt;
for (let i = 1; i < arguments.length; ++i)
args[i] = arguments[i];
console.error.apply(console, args);
} else {
console.error(fmt);
}
};

exports.trace = function(msg) {
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-util-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const common = require('../common');
const assert = require('assert');
const internalUtil = require('internal/util');
const spawnSync = require('child_process').spawnSync;

function getHiddenValue(obj, name) {
return function() {
Expand All @@ -30,3 +31,12 @@ try {
}

assert(/bad_syntax\.js:1/.test(arrowMessage));

const args = [
'--expose-internals',
'-e',
"require('internal/util').error('foo %d', 5)"
];
const result = spawnSync(process.argv[0], args, { encoding: 'utf8' });
assert.strictEqual(result.stderr.indexOf('%'), -1);
assert(/foo 5/.test(result.stderr));

0 comments on commit 0b43c08

Please sign in to comment.