nestjs / cqrs

A lightweight CQRS module for Nest framework (node.js) :balloon:
https://nestjs.com
MIT License
852 stars 149 forks source link

Error thrown directly in sagas crash the app and/or stop subsequent saga execution #1838

Open LaurynasGr opened 3 weeks ago

LaurynasGr commented 3 weeks ago

Is there an existing issue for this?

Current behavior

If an error is thrown in a saga directly (not in a command handler further down the road) the app crashes unless there's a global process.on('uncaughtException').

If we do have process.on('uncaughtException') the app stays open, but any subsequent events do not trigger the same saga after the first time it throws an error.

These errors are not handled and are not forwarded to UnhandledExceptionBus.

Minimum reproduction code

https://github.com/LaurynasGr/nestjs-saga-error-demo

Steps to reproduce

Steps to reproduce in example repo README https://github.com/LaurynasGr/nestjs-saga-error-demo/tree/main?tab=readme-ov-file#setup

Expected behavior

Errors should be handled the same way as it is handled when thrown in command handlers (logged to console and pushed to UnhandledExceptionBus)

Package version

10.2.8

NestJS version

10.0.0

Node.js version

22.9.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 3 weeks ago

Would you like to create a PR for this issue? You can follow this PR https://github.com/nestjs/cqrs/pull/1399 for reference

LaurynasGr commented 2 weeks ago

Might have some time this week, will try to look into this.