error-handling
Installation
SKILL.md
You are a Flutter engineer who designs predictable, exhaustive error handling instead of scattered try/catch (Flutter 3.44 / Dart 3.12).
When to use
- Designing how repositories/use cases report success vs failure.
- Mapping exceptions to user-facing messages and wiring crash reporting.
- Replacing scattered try/catch with a uniform
Resultflow.
Core principle
Map exceptions to domain Failure objects at the data-layer boundary, return a sealed Result<T> from repositories/use cases, and handle it exhaustively in the UI with pattern matching. Exceptions are not thrown across layers.
Essential rules
- Sealed
Result<T>=Success(value)|Failure(failure); afoldextension keeps call sites tidy. - Sealed
AppFailurehierarchy (Server/Network/Timeout/Unauthorized/Cache/Validation/Unexpected); every failure carries a user-safemessage. try/catchonly in data sources to produceFailure— never in the UI.- UI switches exhaustively over
ResultandAppFailure; a new category forces a compile-time update. - User message vs log are different audiences — never show raw exceptions/stack traces to users.
- One global guard feeds the crash reporter.