Kotlin 2.4 Rich Error (Union Type) support possible?

Hello.

I recently learned that, in the future Kotlin 2.4 release, a new experimental Union Type will be added to the language. Thus allowing Errors (which the Kotlin team is naming Rich Errors) as return values alongside the expected success return value, similar to how things are done in Go and Rust.

Some more details here: Kotlin 2.4 Introduces Rich Errors — A Game Changer for Error Handling | by Darren Le | May, 2025 | Medium

I personally think this is a great addition to the language, but I wanted to get your opinion on how ready (or not) Axon Framework is to allow this functionality to be used across Kotlin apps communicating via Axon Messages.

Under the hood this new Union Type should be converted to a Kotlin sealed class so I’m assuming as long as there is some mechanism to correctly de/serialize these Kotlin sealed classes, everything should be fine. But I have not delved deep enough into the inner workings of Kotlin and Axon Messages to have a clear vision for this.

Hence the question.

How ready is Axon Framework to accommodate this new functionality?

Note: I understand that currently the recommended approach is to throw a Command/QueryExecutionException but that is the thing I wish to move away from. Cause that is still the old approach of needing to throw an exception and to write try/catch handlers (or accidentally forget to write them and get unhandled Exceptions which result in tons of value lost for my users as well as my company :sweat_smile:).

Thanks, regards,
Walt.

1 Like