AxonFramework / AxonFramework

Framework for Evolutionary Message-Driven Microservices on the JVM
https://axoniq.io/
Apache License 2.0
3.32k stars 790 forks source link

Validate exception usage #3092

Open smcvb opened 2 months ago

smcvb commented 2 months ago

Description

Exceptions underwent multiple iterations during the framework's development, and new ideas and concepts (such as transient/non-transient) were added. However, given that a lot of these exceptions, by being a class can have only one parent, it became difficult to evolve the exception handling mechanisms in a consistent way. Some framework exceptions rely directly on Throwable, others on AxonException, or AxonTransientException, and then there are also RemoteExceptions.

Since reorganizing this hierarchy will most likely introduce breaking changes, it shouldn’t be done in a minor release but rather as part of Axon Framework 5.

A lot of the code assumes all the errors/exceptions that can happen are Throwable, which is fine for most cases but restricts the framework's handling of failing functions as if they were local failures. AF 4.2 introduced the removal of the Throwable hierarchy at the lowest (message) level, but it would be beneficial to treat all failures as first-class error objects that are not necessarily JVM exceptions. At least, not treat them as exceptions for as long as we don’t have to. In addition, the exposed class hierarchy might rely on marker interfaces instead of only classes that extend Throwable.

Hence, we should validate if exception usages are as desired throughout Axon Framework. For example, the AbstractChildEntityDefinition implementations throw an AxonConfigurationException, while an AggregateModellingException would be better placed.

When picking this up we should probably also have proper documentation and/or some kind of diagram to make sure in the future we use exceptions consistently.

Actions