-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node: Add 'listenererror' in all entities #1228
Conversation
- 'listenererror' event is emitted when an event listener throws (only if it's a synchronous error, otherwise an unhandled rejection will happen anyway). - Usage: ```ts consumer.on('listenererror', (eventName, error) => { ... }); ``` - Related to ongoing issue #1188 (but it's not fixing it at all, this is just a tool that should be helpful in that issue).
To be clear: in this PR, if anything throws within any dataConsumer or dataProducer event listener in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
So, if an event listener throws an error, a new |
So you literally mean emitting "error" instead of "listenererror" within safeEmit() right? It makes sense. Only problem is that we loose the "eventName" argument but we may emit a custom Error class with that field exposed by a public getter. |
What I mean is, from the Node.js docs:
|
That's the classic controversial documentation that doesn't honor reality: Emitting "error" event without an "error" event listener should exit the process (yes, it does):import { EventEmitter } from 'node:events';
import * as http from 'node:http';
const server = http.createServer((req, res) =>
{
res.writeHead(200);
res.end("bye");
});
server.listen(5005, '0.0.0.0', () => console.log('server listening'));
const emitter = new EventEmitter();
emitter.on('foo', () =>
{
console.log(
'"foo" event, emitting unhandled "error" event that should terminate the process (but it does not)'
);
emitter.emit('error', new TypeError('LALALA'));
});
setTimeout(() =>
{
console.log('timer expired, emitting "foo"');
emitter.emit("foo");
console.log('"foo" emitted');
}, 2000); Output:
Throwing an error within an event listener should generate "error" event (but it doesn't):import { EventEmitter } from 'node:events';
import * as http from 'node:http';
const server = http.createServer((req, res) =>
{
res.writeHead(200);
res.end("bye");
});
server.listen(5005, '0.0.0.0', () => console.log('server listening'));
const emitter = new EventEmitter();
emitter.on('error', (error) =>
{
console.log('"error" event: %s', String(error));
});
emitter.on('foo', () =>
{
console.log(
'"foo" event, throwing an error that should produce an "error" event (but it does not)'
);
throw new Error('LALALA');
});
setTimeout(() =>
{
console.log('timer expired, emitting "foo"');
emitter.emit("foo");
console.log('"foo" emitted');
}, 2000); Output:
|
If we make our |
I don't think it should emit an
Agree, fair enough. We can consider it for the 4.0 version, specially regarding all places where |
Yes. |
Bonus Tracks:
test.only
intest-Producer.ts
and fix some tests in that file.