-
Notifications
You must be signed in to change notification settings - Fork 57
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
How to handle errors thrown from defineCommand / defineEvent handlers? #152
Comments
These type of errors should theoretically be catched via normal, error argument in the handle callback or as uncaughtException, i.e: process.on('uncaughtException', function (err) {
}) Can you try to update to v2.14.78 ? |
Regarding the custom command handler, you are free to use it and to call external operations, etc... |
thank you, now it works. if (err instanceof ValidationError || err instanceof BusinessRuleError ||
err instanceof AggregateDestroyedError || err instanceof AggregateConcurrencyError ||
err instanceof DuplicateCommandError) {
dotty.put(evt, this.definitions.event.payload, {
command: cmd,
reason: {
name: err.name,
message: err.message,
more: err.more
}
});
if (!!this.definitions.event.revision && dotty.get(evt, this.definitions.event.revision) === undefined && err.more && err.more.aggregateRevision > -1) {
dotty.put(evt, this.definitions.event.revision, err.more.aggregateRevision);
}
} else {
evt = null;
} in reason of this, if error occurred in commandHandler (for example TypeError), we can't rollback our Saga and as result end user will see the hanged operation. I think we should do rollbacks where it possible even if error was made by programmer on code level. |
When Designing this piece of code I discussed this with other persons. |
About
I understand that we can use it in emergency cases if by some reason callback handler was not executed with error object in first argument. But this situation does not allow us to log this error by our OpenTracing server (Jaeger) because to close current trace we need to pass trace id to error handler of Jaeger. In I made this note to explain why we should try to pass error in handler callback in all cases where it possible and leave handling by |
But then in case of the exception inside command handler, we have to deal with unfinished (not completed nor rolled back) saga and manually rollback actions performed before this exception. On the other hand, imagine that command handler catch any exceptions and thrown them as, let me say, CommandHandlerError and this error type would have listed in the code @imissyouso noted above (with ValidationError, BusinessRuleError etc). Then "commandRejected" event will be produced in a natural way, as it was ValidationError or BusinessRuleError, and the saga would be rolled back. I understand that having an unhandled exception in command is an unusual situation, but now we have to catch it and do produce "commandRejected" manually, and it looks kinda strange to me because other types of exceptions produce it by themselves. |
the strange way to punish programmers especially if we are talking about highload systems where in reason of programmer error we will have to rollback all hanged sagas manually - sounds bad for business :) |
Always happy for a PR. |
currently we are at stage of investigating and collecting potential issues before the real start of development. As soon as we will do it wait PR from us :) |
Hi!
For example:
how to handle such type of errors?
Approach listed below doesn't help.
This problem is similar for defineViewBuilder of eventdenormalizer. Can't catch errors there too.
another a little question:
Why custom command handler is so bad?
what if I need to make external operation like 3rd party API http call and generate event with resulted data without saving to eventstore. This event then can be handled by sagas to generate command to update required aggregate.
The text was updated successfully, but these errors were encountered: