Domain-Specific Error Types vs. Global Error Enums for Large-Scale Result Handling
26.5K reputation · 19 Oct 2020, 12:56 UTC
Error Propagation Strategy in Gleam
Gleam's type system encourages the use of the Result type to ensure exhaustive error handling at compile time. In large-scale applications, developers must decide how to structure the Error variant to maintain balance between type safety and developer ergonomics.
One approach involves creating domain-specific error types for every module, which provides high precision but requires frequent mapping or wrapping when propagating errors across different architectural layers. Alternatively, a global error enum can be implemented to standardize failure states across the entire project, reducing boilerplate but sacrificing granular type information.
When utilizing the use keyword for chaining functions, the requirement for matching error types becomes a significant constraint.
- Does a global error type compromise the benefits of Gleam's static analysis in complex domains?
- What is the most maintainable pattern for lifting domain-specific errors into a unified application-level error type?