Skip to content

Commit

Permalink
events: make memory leak warning name more verbose
Browse files Browse the repository at this point in the history
Switch from a generic `Warning` to the more specific
`MaxListenersExceededWarning`.

Ref: #8298
PR-URL: #8341
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
addaleax committed Sep 4, 2016
1 parent 7e8d994 commit 983775d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/api/events.md
Expand Up @@ -285,6 +285,7 @@ The emitted warning can be inspected with [`process.on('warning')`][] and will
have the additional `emitter`, `type` and `count` properties, referring to
the event emitter instance, the event’s name and the number of attached
listeners, respectively.
Its `name` property is set to `'MaxListenersExceededWarning'`.

### emitter.addListener(eventName, listener)
<!-- YAML
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Expand Up @@ -259,7 +259,7 @@ function _addListener(target, type, listener, prepend) {
const w = new Error('Possible EventEmitter memory leak detected. ' +
`${existing.length} ${type} listeners added. ` +
'Use emitter.setMaxListeners() to increase limit');
w.name = 'Warning';
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-max-listeners-warning.js
Expand Up @@ -11,7 +11,7 @@ e.setMaxListeners(1);

process.on('warning', common.mustCall((warning) => {
assert.ok(warning instanceof Error);
assert.strictEqual(warning.name, 'Warning');
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
assert.strictEqual(warning.emitter, e);
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, 'event-type');
Expand Down

0 comments on commit 983775d

Please sign in to comment.