Here we replace the Failure(null) that we were using to signal errors with Failures containing specific information about what went wrong. We use sealed interfaces so that code that deals with the Failure can know all the subtypes, and hence reasons for failure.
This is Part 27 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
• All Gilded Rose Episodes
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd
This sub-series on error handling is also a playlist
• Kotlin Error Handling - Exceptions, N...
If you like this, you’ll probably like the book Java to Kotlin, A Refactoring Guidebook
http://java-to-kotlin.dev. Chapter 19 covers error handling.
The music is thanks to http://toolofgod.com/my-music/royalty...