Error handling in Query trait implementations #33
-
It doesn't come up in the
However, in the
These are all things that are usually very fallible which is why What I don't understand is why Queries should be infallible and why they would not be "bubbled up" using A workaround is to panic and use something like tower-http's catch_panic and string matching of the message but this goes against idiomatic Rust's preference of not using panics for error handling and seems more obfuscated code-wise than creating a specific layer/handler. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @johnbcodes. The reason that queries are infallible in the framework is that in CQRS the command handler work on the aggregate is always considered the sole source of truth. Any logic that could cause the command to fail should be inside the aggregate. Without that separation of aggregate logic and query updates we would lose a lot of the benefits that CQRS provides us (API decoupling, horizontal scaling, state error debugging, etc.). Application of events to queries can absolutely fail IRL. In CQRS though you need to find other ways to deal with it. Many times this will be putting the view in question into some sort of an error state (e.g., add a flag to show the customer that "something is wrong, please call customer service..."). These individual failure cases must be dealt with as you would in an event processing system rather than in a more common webapp style application. |
Beta Was this translation helpful? Give feedback.
Hi @johnbcodes.
The reason that queries are infallible in the framework is that in CQRS the command handler work on the aggregate is always considered the sole source of truth. Any logic that could cause the command to fail should be inside the aggregate. Without that separation of aggregate logic and query updates we would lose a lot of the benefits that CQRS provides us (API decoupling, horizontal scaling, state error debugging, etc.).
Application of events to queries can absolutely fail IRL. In CQRS though you need to find other ways to deal with it. Many times this will be putting the view in question into some sort of an error state (e.g., add a flag to show the customer that "someth…