Skip to content

Commit 983775d

Browse files
committed
events: make memory leak warning name more verbose
Switch from a generic `Warning` to the more specific `MaxListenersExceededWarning`. Ref: #8298 PR-URL: #8341 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 7e8d994 commit 983775d

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

doc/api/events.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ The emitted warning can be inspected with [`process.on('warning')`][] and will
285285
have the additional `emitter`, `type` and `count` properties, referring to
286286
the event emitter instance, the event’s name and the number of attached
287287
listeners, respectively.
288+
Its `name` property is set to `'MaxListenersExceededWarning'`.
288289

289290
### emitter.addListener(eventName, listener)
290291
<!-- YAML

lib/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function _addListener(target, type, listener, prepend) {
259259
const w = new Error('Possible EventEmitter memory leak detected. ' +
260260
`${existing.length} ${type} listeners added. ` +
261261
'Use emitter.setMaxListeners() to increase limit');
262-
w.name = 'Warning';
262+
w.name = 'MaxListenersExceededWarning';
263263
w.emitter = target;
264264
w.type = type;
265265
w.count = existing.length;

test/parallel/test-event-emitter-max-listeners-warning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ e.setMaxListeners(1);
1111

1212
process.on('warning', common.mustCall((warning) => {
1313
assert.ok(warning instanceof Error);
14-
assert.strictEqual(warning.name, 'Warning');
14+
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
1515
assert.strictEqual(warning.emitter, e);
1616
assert.strictEqual(warning.count, 2);
1717
assert.strictEqual(warning.type, 'event-type');

0 commit comments

Comments
 (0)