mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
console: fixup console.dir() error handling
Apply the `console: do not emit error events` changes properly
to `console.dir()`.
This was overlooked in f18e08d820
(https://github.com/nodejs/node/pull/9744).
Ref: https://github.com/nodejs/node/commit/f18e08d820dde161788d95a5603546ceca021e90#commitcomment-20934407
PR-URL: https://github.com/nodejs/node/pull/11443
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
3 files changed
+49
-42
No files matched your search
+4
-1
@@ -103,7 +103,10 @@ Console.prototype.error = Console.prototype.warn;
|
||||
|
||||
Console.prototype.dir = function dir(object, options) {
|
||||
options = Object.assign({customInspect: false}, options);
|
||||
write(this._ignoreErrors, this._stdout, `${util.inspect(object, options)}\n`);
|
||||
write(this._ignoreErrors,
|
||||
this._stdout,
|
||||
`${util.inspect(object, options)}\n`,
|
||||
this._stdoutErrorHandler);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,14 +4,16 @@ const { Console } = require('console');
|
||||
const { Writable } = require('stream');
|
||||
const assert = require('assert');
|
||||
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
process.nextTick(callback, new Error('foobar'));
|
||||
})
|
||||
});
|
||||
for (const method of ['dir', 'log', 'warn']) {
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
process.nextTick(callback, new Error('foobar'));
|
||||
})
|
||||
});
|
||||
|
||||
const c = new Console(out, out, true);
|
||||
const c = new Console(out, out, true);
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
c.log('abc');
|
||||
});
|
||||
assert.doesNotThrow(() => {
|
||||
c[method]('abc');
|
||||
});
|
||||
}
|
||||
@@ -4,44 +4,46 @@ const { Console } = require('console');
|
||||
const { Writable } = require('stream');
|
||||
const assert = require('assert');
|
||||
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
callback(new Error('foobar'));
|
||||
})
|
||||
});
|
||||
for (const method of ['dir', 'log', 'warn']) {
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
callback(new Error('foobar'));
|
||||
})
|
||||
});
|
||||
|
||||
const c = new Console(out, out, true);
|
||||
const c = new Console(out, out, true);
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
c.log('abc');
|
||||
});
|
||||
}
|
||||
assert.doesNotThrow(() => {
|
||||
c[method]('abc');
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
throw new Error('foobar');
|
||||
})
|
||||
});
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
throw new Error('foobar');
|
||||
})
|
||||
});
|
||||
|
||||
const c = new Console(out, out, true);
|
||||
const c = new Console(out, out, true);
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
c.log('abc');
|
||||
});
|
||||
}
|
||||
assert.doesNotThrow(() => {
|
||||
c[method]('abc');
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
setImmediate(() => callback(new Error('foobar')));
|
||||
})
|
||||
});
|
||||
{
|
||||
const out = new Writable({
|
||||
write: common.mustCall((chunk, enc, callback) => {
|
||||
setImmediate(() => callback(new Error('foobar')));
|
||||
})
|
||||
});
|
||||
|
||||
const c = new Console(out, out, true);
|
||||
const c = new Console(out, out, true);
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
c.log('abc');
|
||||
});
|
||||
assert.doesNotThrow(() => {
|
||||
c[method]('abc');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user