moleculer icon indicating copy to clipboard operation
moleculer copied to clipboard

Feature/issue 991 ensure error handler throws to the transit layer

Open JordanPawlett opened this issue 4 years ago • 6 comments

: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

JordanPawlett avatar Aug 27 '21 09:08 JordanPawlett

Handles https://github.com/moleculerjs/moleculer/issues/991

JordanPawlett avatar Aug 27 '21 09:08 JordanPawlett

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.

icebob avatar Aug 28 '21 18:08 icebob

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.

Ultimately the thrown error is caught and handled in the transit messageHandler, and resolved to turn false. Does this not negate this problem?

JordanPawlett avatar Aug 28 '21 18:08 JordanPawlett

Ultimately the thrown error is caught and handled in the transit messageHandler, and resolved to turn false. Does this not negate this problem?

Yeah, if the event is received via transported. Locally created events won't be handled.

image

icebob avatar Aug 30 '21 07:08 icebob

Ultimately the thrown error is caught and handled in the transit messageHandler, and resolved to turn false. Does this not negate this problem?

Yeah, if the event is received via transported. Locally created events won't be handled.

image

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?

JordanPawlett avatar Aug 30 '21 08:08 JordanPawlett

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

icebob avatar Sep 01 '21 16:09 icebob