Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: fixup console.dir() error handling #11443

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};


Expand Down
20 changes: 11 additions & 9 deletions test/parallel/test-console-async-write-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
82 changes: 42 additions & 40 deletions test/parallel/test-console-sync-write-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
})
});

const c = new Console(out, out, true);

assert.doesNotThrow(() => {
c.log('abc');
});
}

{
const out = new Writable({
write: common.mustCall((chunk, enc, callback) => {
throw new Error('foobar');
})
});

const c = new Console(out, out, true);

assert.doesNotThrow(() => {
c.log('abc');
});
}

{
const out = new Writable({
write: common.mustCall((chunk, enc, callback) => {
setImmediate(() => callback(new Error('foobar')));
})
});

const c = new Console(out, out, true);

assert.doesNotThrow(() => {
c.log('abc');
});
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);

assert.doesNotThrow(() => {
c[method]('abc');
});
}

{
const out = new Writable({
write: common.mustCall((chunk, enc, callback) => {
throw new Error('foobar');
})
});

const c = new Console(out, out, true);

assert.doesNotThrow(() => {
c[method]('abc');
});
}

{
const out = new Writable({
write: common.mustCall((chunk, enc, callback) => {
setImmediate(() => callback(new Error('foobar')));
})
});

const c = new Console(out, out, true);

assert.doesNotThrow(() => {
c[method]('abc');
});
}
}