KotlinSyft
KotlinSyft copied to clipboard
Error communication should use domain objects instead of exceptions
What?
Error management in Syft is all done by exceptions. Though this is a quick solution it is becoming an antipattern.
See here https://phauer.com/2019/sealed-classes-exceptions-kotlin/
Why?
Exceptions break the normal flow of the application and force the clients to be aware of them to prevent the app crashing.
Alternatives already exist providing a more robust approach as modelling the errors with sealed classes, Kotlin Result, Either
or Try
constructions.
Breakdown
- Replace exceptions in the higher levels of the lib one by one by the selected options (sealed class, Kotlin Result, Either, Try).
- Rinse and repeat.
Additional Context
Please note that this is not intended to remove exceptions in the lower levels. Basically that is not possible yet. It's the lib API that should offer other mechanisms.
#249 clears a few of these error handling