diff --git a/lib/events.js b/lib/events.js index dfd0ed57d42e49..eabf5c2cc7fb5c 100644 --- a/lib/events.js +++ b/lib/events.js @@ -171,7 +171,7 @@ EventEmitter.prototype.emit = function emit(type) { er = arguments[1]; if (domain) { if (!er) - er = new Error('Uncaught, unspecified "error" event'); + er = new Error('Unhandled "error" event'); if (typeof er === 'object' && er !== null) { er.domainEmitter = this; er.domain = domain; @@ -182,7 +182,7 @@ EventEmitter.prototype.emit = function emit(type) { throw er; // Unhandled 'error' event } else { // At least give some kind of context to the user - var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); + const err = new Error('Unhandled "error" event. (' + er + ')'); err.context = er; throw err; } diff --git a/test/parallel/test-event-emitter-errors.js b/test/parallel/test-event-emitter-errors.js index 2b4a93ae9808df..be4f4007f096df 100644 --- a/test/parallel/test-event-emitter-errors.js +++ b/test/parallel/test-event-emitter-errors.js @@ -5,6 +5,10 @@ const assert = require('assert'); const EE = new EventEmitter(); -assert.throws(function() { +assert.throws(() => { EE.emit('error', 'Accepts a string'); -}, /Accepts a string/); +}, /^Error: Unhandled "error" event\. \(Accepts a string\)$/); + +assert.throws(() => { + EE.emit('error', {message: 'Error!'}); +}, /^Error: Unhandled "error" event\. \(\[object Object\]\)$/);