Replies: 1 comment 1 reply
-
I think you're confusing concepts although your description isn't clear enough that I can pinpoint it exactly. Event emitters are synchronous, async functions are not. If you mix them without being mindful of that, then yes, it's going to sting. Not a bug though. I'm going to convert this to a discussion. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version
20.13.1, probably all others too.
Platform
Subsystem
No response
What steps will reproduce the bug?
When an async function throws an error during an event emitter callback, the error is not caught by catch block at the time of execution its event but only after all events are done. This behavior:
Reproduction:
How often does it reproduce? Is there a required condition?
Always. No special Condition.
What is the expected behavior? Why is that the expected behavior?
All errors thrown in async functions called from event handlers should be catchable by surrounding try/catch blocks at the time of the function call.
What do you see instead?
All function calls first get executed and only then all the catch blocks get executed. (Immagine what would happen with some complex Error Handling)
Additional information
Impact: This affects all event emitter usage with async handlers (MQTT clients, OPCUA subscriptions,...)
Maybe this is technically correct per the spec, but creates dangerous real-world behavior, if one wants to handle all exceptions in an ExceptionHandler outside from the called async function.
Beta Was this translation helpful? Give feedback.
All reactions