Permalink
Browse files

events: update and clarify error message

Update error message that's thrown when no error listeners are attached
to an emitter.

PR-URL: #10387
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information...
ctide authored and jasnell committed Dec 21, 2016
1 parent cfc8422 commit 2141d374527337f7e1c74c9efad217b017d945cf
Showing with 8 additions and 4 deletions.
  1. +2 −2 lib/events.js
  2. +6 −2 test/parallel/test-event-emitter-errors.js
View
@@ -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;
}
@@ -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\]\)$/);

0 comments on commit 2141d37

Please sign in to comment.