moleculer
moleculer copied to clipboard
Feature/issue 991 ensure error handler throws to the transit layer
:memo: Description
Error-handler should re-throw an event error to ensure the messageHandler can return the correct result to the transporter.
:dart: Relevant issues
:gem: Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
:checkered_flag: Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I have commented my code, particularly in hard-to-understand areas
Handles https://github.com/moleculerjs/moleculer/issues/991
I need to think about it because it can be a breaking change. If somebody throws errors in event handlers in the current version it' catcher and logged. But after this PR, the error will be thrown further and it will cause UnhandledPromiseRejection and as of Node 15, it will crashes the process, not just print a warning.
I need to think about it because it can be a breaking change. If somebody throws errors in event handlers in the current version it' catcher and logged. But after this PR, the error will be thrown further and it will cause
UnhandledPromiseRejectionand as of Node 15, it will crashes the process, not just print a warning.
Ultimately the thrown error is caught and handled in the transit messageHandler, and resolved to turn false. Does this not negate this problem?
Ultimately the thrown error is caught and handled in the transit
messageHandler, and resolved to turnfalse. Does this not negate this problem?
Yeah, if the event is received via transported. Locally created events won't be handled.

Ultimately the thrown error is caught and handled in the transit
messageHandler, and resolved to turnfalse. Does this not negate this problem?Yeah, if the event is received via transported. Locally created events won't be handled.
Would you be able to point me at the entryPoint for receiving local events rather than via the transporter.
What about a config option to allow the event handler to throw? Or only allow it when preferLocal is false?
There are multiple places where local events triggered because it depends on the type (emit or broadcast). Here is the emitted: https://github.com/moleculerjs/moleculer/blob/master/src/service-broker.js#L1366 Here is the broadcasted: https://github.com/moleculerjs/moleculer/blob/master/src/service-broker.js#L1648