Flutter error handling
Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/flutter-error-handling
π§ The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.
npx -y skills add ComeOnOliver/skillshub --skill flutter-error-handlingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
What its author says it does
Copied from the file, not written here
Functional error handling with Either/Failure. ALWAYS consult when writing repositories, handling exceptions, defining failures, or using Either in any Flutter layer β not just when setting up error handling. (triggers: lib/domain/**, lib/infrastructure/**, Either, fold, Left, Right, Failure, dartz)
SKILL.md
2.2 KB, as published. Nobody here has run it
Error Handling
Priority: P1 (HIGH)
Standardized functional error handling using dartz and freezed failures.
Implementation Guidelines
- Either Pattern: Return Either<Failure, T> from repositories. No exceptions in UI/BLoC.
- Failures: Define domain-specific failures using @freezed unions (e.g.,
UnauthorizedFailure,OutOfStockFailure). - Mapping: Infrastructure catches Exception (e.g.,
DioException) and returns Left(Failure). Never rethrow to UI. - Consumption: Use .fold(failure, success) in BLoC to emit corresponding states. Remove try/catch from BLoC.
- Typed Errors: Use
left(Failure())andright(Value())fromDartz. - Low-Cardinality Logging: Use stable message templates; pass variable data via metadata/context.
- Layer Restriction: try/catch only in Infrastructure. UI/Application/BLoC layers should not catch.
- Localization: Use
failure.failureMessage(returns TRObject or localized string) for UI-safe text. - Right/Left Restriction: Only Infrastructure may construct
Right()/Left(). - No Silent Catch: Never swallow errors without logging or a documented retry.
Reference & Examples
For Failure definitions and API error mapping: See references/REFERENCE.md.
Anti-Patterns
- β
try { β¦ } catch (e) { emit(ErrorState()); }in BLoC β try/catch belongs only in Infrastructure; BLoC receivesEither, then folds - β
Left(Failure('Something went wrong'))using a plainStringβ define typed@freezedFailure subclasses for each domain error - β
catch (e) {}empty catch β always log and propagate; never swallow silently - β Throwing
Exceptionfrom a repository β returnLeft(Failure)instead; exceptions must not cross the infrastructure boundary
Related Topics
layer-based-clean-architecture | bloc-state-management