Skip to content
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

EventEmitter2 is not handling throw exception and closing app #298

Open
Mupli opened this issue Mar 5, 2023 · 4 comments
Open

EventEmitter2 is not handling throw exception and closing app #298

Mupli opened this issue Mar 5, 2023 · 4 comments

Comments

@Mupli
Copy link

Mupli commented Mar 5, 2023

My expectation is that if an error is thrown within an event listener it should be handled by EE2 and app will not be closed . or we will be able to handle using try catch ? So it is not the case here.

In EE node:events they use 'error' handler for this case

old ee examples:

ee.on('error', function (err) {
    console.log(err);
});

ee.on('some.other.event', async function () {
    throw Error('blah');
});

ee.emit('some.other.event');
@mathulbrich
Copy link

Same issue here. But it seems to be possible to catch the error when we use emitAsync method.

@elcrostatina
Copy link

Same issue here. But it seems to be possible to catch the error when we use emitAsync method.

same here. Could you please show me an example of how you manage to make it work with emitAsync ?

@mathulbrich
Copy link

Same issue here. But it seems to be possible to catch the error when we use emitAsync method.

same here. Could you please show me an example of how you manage to make it work with emitAsync ?

Basically just doing a catch on your emitAsync call. It seems that with emitAsync is possible to catch errors, but with just emit isn't.

try {
    ee.emit("some.other.event");
} catch {
    console.log("catched!");
}
// Output: Error: blah

try {
    await ee.emitAsync("some.other.event");
} catch {
    console.log("catched!");
}
// Output: catched!

@mathulbrich
Copy link

Oh, I have realized some tests here and identified that this problem only occours because the callback for some.other.event is a async function, but the emit have a sync behavior. So this problem is more about an unhandled Promise, not a bug at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants