Best Practices
These pages collect the design principles that make ZIO's typed error channel pay off in real applications. Following them keeps error signatures precise, prevents unexpected errors from leaking into the type system, and avoids logging patterns that hide errors rather than surface them.
- Algebraic Data Types — model domain errors as sealed traits and case classes so the compiler enforces exhaustive handling.
- Union Types — use Scala 3 union types to compose unrelated error types without a shared supertype, keeping error signatures precise.
- Don't Type Unexpected Errors — use
orDieandrefineOrDieto separate recoverable errors from application-killing defects rather than widening the error type. - Don't Reflexively Log Errors — rely on ZIO's typed error propagation instead of logging errors at every call site.