Skip to content

Commit

Permalink
events: update and clarify error message
Browse files Browse the repository at this point in the history
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 Mar 24, 2017
1 parent cfc8422 commit 2141d37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-event-emitter-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.