Agent-skills-standard flutter-error-handling
Implement functional error recovery with Either/Failure patterns. Use when writing repositories, handling exceptions, defining failures, or using Either in any Flutter layer. (triggers: lib/domain/**, lib/infrastructure/**, Either, fold, Left, Right, Failure, dartz)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/flutter/flutter-error-handling" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-flutter-error-handling && rm -rf "$T"
manifest:
skills/flutter/flutter-error-handling/SKILL.mdsource content
Error Handling
Priority: P1 (HIGH)
Implementation Workflow
- Define failures — Create domain-specific failures using
unions (e.g.,@freezed
,UnauthorizedFailure
).OutOfStockFailure - Return Either — Repositories return
. No exceptions in UI/BLoC.Either<Failure, T> - Catch in Infrastructure only — Infrastructure catches exceptions (e.g.,
) and returnsDioException
. Never rethrow to UI.Left(Failure) - Fold in BLoC — Use
in BLoC to emit corresponding states. Remove try/catch from BLoC..fold(failure, success) - Localize messages — Use
(returnsfailure.failureMessage
or localized string) for UI-safe text.TRObject - Log with stable templates — Use low-cardinality message templates; pass variable data via metadata/context.
- No Silent Catch: Never swallow errors without logging or documented retry.
- Crashlytics Routing: All UI/BLoC
blocks MUST route errors viacatch
for observability and type-safe UI messages.AppLogger.error(AppException.fromException(e).message, error: e, stackTrace: st)
Repository & BLoC Examples
See implementation examples for repository error mapping and BLoC consumption patterns.
Reference & Examples
For Failure definitions and API error mapping: See references/REFERENCE.md.
Anti-Patterns
- No Try-Catch in BLoC: BLoC receives
andEither
; try/catch belongs in Infrastructurefolds - No Plain String Failures: Define typed
Failure subclasses instead of@freezedLeft('Something went wrong') - No Empty Catch Blocks: Always log and propagate; never swallow errors silently
- No Repositories Throwing Status: Return
instead of throwingLeft(Failure)Exception - No Missing Log Registration: Use
in BLoC/UIAppLogger.error
to ensure Crashlytics tracking and type-safe UI messagescatch
Related Topics
layer-based-clean-architecture | bloc-state-management