Browse Source

util: pass on additional error() args

This fixes breakage introduced in 94b9948d63 when writing the max
EventEmitter listeners warning to stderr.

PR-URL: https://github.com/nodejs/node/pull/4279
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
process-exit-stdio-flushing
Brian White 9 years ago
parent
commit
0b43c08f44
  1. 11
      lib/internal/util.js
  2. 10
      test/parallel/test-util-internal.js

11
lib/internal/util.js

@ -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) {

10
test/parallel/test-util-internal.js

@ -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() {
@ -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));

Loading…
Cancel
Save