events: update and clarify error message
Update error message that's thrown when no error listeners are attached to an emitter. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
cfc8422a68
commit
2141d37452
@ -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\]\)$/);
|
||||
|
Loading…
x
Reference in New Issue
Block a user