Error Modeling

Failure as part of the design: separating expected business failure from validation, dependency failure and outright bugs, and choosing how each is expressed in types.

Error Modeling
▶ lab

Failure is part of the design, not an appendix to it. Expected business failure, validation failure, dependency failure and programming bug are four categories with four different correct responses.

Q · Which failures belong in my domain model, which are translation, and which are simply bugs I must never handle?
An Error Taxonomy That Survives Contact

Six kinds — InvalidInput, NotFound, Conflict, Unauthorized, DependencyTimeout, InternalBug — chosen because each one gets a different response. The taxonomy is a type-level decision, not a status-code table.

Q · How many error kinds should my codebase have, and what makes one kind genuinely different from another?
Result Types

`Result<Payment, PaymentError>` puts expected failure in the return type, where the compiler can insist somebody deals with it. What that costs depends enormously on the language.

Q · When is it worth making failure part of the return type rather than a separate control-flow path?
Exceptions, Where They Help and Where They Hide the Flow

A non-local jump is exactly right for a failure nobody local can answer, and exactly wrong for an outcome the caller was supposed to decide about. The dividing line is not a rule about exceptions.

Q · Which failures deserve a non-local jump, and when has an exception become a control-flow mechanism in disguise?
Error Boundaries
▶ lab

Every failure has a point where it stops being handled locally and becomes somebody else's problem. Choosing that point deliberately is a design decision; discovering it in production is not.

Q · Where should a failure stop travelling, and who owns it once it crosses that line?
Swallowed Errors
▶ lab

`catch {}` is the visible version. The interesting one is an interface that can only return success or failure, so the code that half-worked has nowhere honest to put the truth.

Q · Why does a failure get silently absorbed, and what does that tell me about the interface it was absorbed inside?