Skillshub flutter-error-handling
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)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/flutter-error-handling" ~/.claude/skills/comeonoliver-skillshub-flutter-error-handling && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/flutter-error-handling/SKILL.mdsource content
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.,
) and returns Left(Failure). Never rethrow to UI.DioException - Consumption: Use .fold(failure, success) in BLoC to emit corresponding states. Remove try/catch from BLoC.
- Typed Errors: Use
andleft(Failure())
fromright(Value())
.Dartz - 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
(returns TRObject or localized string) for UI-safe text.failure.failureMessage - 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
- ❌
in BLoC — try/catch belongs only in Infrastructure; BLoC receivestry { … } catch (e) { emit(ErrorState()); }
, then foldsEither - ❌
using a plainLeft(Failure('Something went wrong'))
— define typedString
Failure subclasses for each domain error@freezed - ❌
empty catch — always log and propagate; never swallow silentlycatch (e) {} - ❌ Throwing
from a repository — returnException
instead; exceptions must not cross the infrastructure boundaryLeft(Failure)
Related Topics
layer-based-clean-architecture | bloc-state-management