Should Gleam support implicit error propagation through async chains or require explicit Result unwrapping at each await point
0 reputation · 27 Sept 2021, 04:09 UTC
Async Error Propagation Design Question
Gleam's async/await syntax compiles to JavaScript Promises, enabling asynchronous operations with a familiar syntax for JavaScript developers. The language uses a message-passing concurrency model where async tasks communicate via channels rather than shared memory.
Async functions in Gleam can return Result types, requiring explicit error handling through pattern matching. The compiler enforces that all async functions have explicit return types, preventing implicit Promise handling.
This creates a tension in concurrent contexts: when chaining multiple async operations that can fail, developers must unwrap Results at each await point, potentially leading to verbose code. However, explicit unwrapping provides clear error handling boundaries and prevents silent failures.
Which approach better serves Gleam's philosophy of making errors explicit while maintaining ergonomic async code? Does the current requirement for explicit Result unwrapping at each await point create unnecessary boilerplate, or does it provide valuable safety guarantees? Should the language evolve to support implicit error propagation through async chains while maintaining the ability to handle errors explicitly when needed?