Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
fixup! fixup! events: show inspected error in uncaught 'error' message
  • Loading branch information
addaleax committed Jan 22, 2019
commit b896404078ab40dba699efc826a6a95cfdcd8a7c
19 changes: 10 additions & 9 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ EventEmitter.prototype.emit = function emit(type, ...args) {

// If there is no 'error' event listener then throw.
if (doError) {
let er, stringifiedEr;
let er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
stringifiedEr = er;
try {
const { kExpandStackSymbol } = require('internal/util');
const capture = {};
Expand All @@ -172,14 +171,16 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
throw er; // Unhandled 'error' event
} else {
const { inspect } = require('internal/util/inspect');
try {
stringifiedEr = inspect(er);
} catch {
stringifiedEr = er;
}
}

let stringifiedEr;
const { inspect } = require('internal/util/inspect');
try {
stringifiedEr = inspect(er);
} catch {
stringifiedEr = er;
}

// At least give some kind of context to the user
const errors = lazyErrors();
const err = new errors.ERR_UNHANDLED_ERROR(stringifiedEr);
Expand Down