events: improve max listeners warning · nodejs/node@1f935f8 · GitHub
Skip to content

Commit 1f935f8

Browse files
BridgeARtargos
authored andcommitted
events: improve max listeners warning
This adds the constructor name of the event target to the emitted warning. Right now it's difficult to identify where the leak is actually coming from and having some further information about the source will likely help to identify the source. PR-URL: #27694 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 3ac4a71 commit 1f935f8

4 files changed

Lines changed: 20 additions & 6 deletions

lib/events.js

Lines changed: 6 additions & 2 deletions

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ process.on('warning', common.mustCall((warning) => {
1515
assert.strictEqual(warning.emitter, e);
1616
assert.strictEqual(warning.count, 2);
1717
assert.strictEqual(warning.type, null);
18-
assert.ok(warning.message.includes('2 null listeners added.'));
18+
assert.ok(warning.message.includes(
19+
'2 null listeners added to [EventEmitter].'));
1920
}));
2021

2122
e.on(null, () => {});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ process.on('warning', common.mustCall((warning) => {
1717
assert.strictEqual(warning.emitter, e);
1818
assert.strictEqual(warning.count, 2);
1919
assert.strictEqual(warning.type, symbol);
20-
assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.'));
20+
assert.ok(warning.message.includes(
21+
'2 Symbol(symbol) listeners added to [EventEmitter].'));
2122
}));
2223

2324
e.on(symbol, () => {});

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

Lines changed: 10 additions & 2 deletions

0 commit comments

Comments
 (0)