-
Notifications
You must be signed in to change notification settings - Fork 0
Error Handling
We need a uniform way of handling errors and common definitions of errors, most importantly when it comes to differentiating between technical errors and domain errors because it helps us to track actual bugs in prod, prevents miscommunications and makes the code easier to work with.
We differentiate between technical errors and domain errors.
Technical errors are the result of mistakes on our side. Something like a div by zero because we forgot to check that case.
In a perfect world, we would have no technical errors at all.
Domain errors are errors in how the domain logic is implemented in code, such as bugs or unintended behavior that do not align with the domain’s intended logic. They indicate discrepancies between what the domain requires and how it is executed in the application. E.g. a certain type of name in the domain can only contain lowercase letters, but our app allows uppercase letters aswell.
In a perfect world, we would have no technical errors at all.
Domain violations on the other hand are expected "errors". Once a domain rule is broken somewhere (e.g. a user enters a name containing uppercase letters when only lowercase letters are allowed in the domain), the program is supposed to handle it with a predefined domain violation. This ensures, that the team speaks a common language.
Domain violations appear all over the codebase.
These are straight up bugs. Once we find them, they should be fixed, potentially by implementing and testing for a domain violation.
Places, where domain violations may occur, should be wrapped in Result types to express, that "something may go wrong in there, but we expect that and are going to handle it explicitly". Depending on the cause of the violation, the user might have to be notified, that their action is illegal.