Return Either — Repositories return Either<Failure, T>. No exceptions in UI/BLoC.
Catch in Infrastructure only — Infrastructure catches exceptions (e.g., DioException) and
returns Left(Failure). Never rethrow to UI.
Fold in BLoC — Use .fold(failure, success) in BLoC to emit corresponding states. Remove
try/catch from BLoC.
Localize messages — Use failure.failureMessage (returns TRObject or localized string) for
UI-safe text.
Log with stable templates — Use low-cardinality message templates; pass variable data via
metadata/context.
No Silent Catch: Never swallow errors without logging or a documented retry.
Crashlytics Routing: All UI/BLoC catch blocks MUST route errors via
AppLogger.error(AppException.fromException(e).message, error: e, stackTrace: st) for
observability and type-safe UI messages.
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
❌ try { … } catch (e) { emit(ErrorState()); } in BLoC — try/catch belongs only in
Infrastructure; BLoC receives Either, then folds
❌ Left(Failure('Something went wrong')) using a plain String — define typed @freezed Failure
subclasses for each domain error
❌ catch (e) {} empty catch — always log and propagate; never swallow silently
❌ Throwing Exception from a repository — return Left(Failure) instead; exceptions must not
cross the infrastructure boundary
❌ catch (e) { print(e); } — missing AppLogger.error; errors must be sent to Crashlytics with
the original error and stack trace
1---2name: li-lance-android-seraphim-framework-flutter-error-handling3description: Error Handling4---56# Error Handling78## **Priority: P1 (HIGH)**910Standardized functional error handling using `dartz` and `freezed` failures.1112## Implementation Workflow13141. **Define failures** — Create domain-specific failures using `@freezed` unions (e.g.,15 `UnauthorizedFailure`, `OutOfStockFailure`).162. **Return Either** — Repositories return `Either<Failure, T>`. No exceptions in UI/BLoC.173. **Catch in Infrastructure only** — Infrastructure catches exceptions (e.g., `DioException`) and18 returns `Left(Failure)`. Never rethrow to UI.194. **Fold in BLoC** — Use `.fold(failure, success)` in BLoC to emit corresponding states. Remove20 try/catch from BLoC.215. **Localize messages** — Use `failure.failureMessage` (returns `TRObject` or localized string) for22 UI-safe text.236. **Log with stable templates** — Use low-cardinality message templates; pass variable data via24 metadata/context.257. **No Silent Catch**: Never swallow errors without logging or a documented retry.268. **Crashlytics Routing**: All UI/BLoC `catch` blocks MUST route errors via27 `AppLogger.error(AppException.fromException(e).message, error: e, stackTrace: st)` for28 observability and type-safe UI messages.2930### Repository & BLoC Examples3132See [implementation examples](references/implementation.md) for repository error mapping and BLoC33consumption patterns.3435## Reference & Examples3637For Failure definitions and API error mapping:38See [references/REFERENCE.md](references/REFERENCE.md).3940## Anti-Patterns4142- ❌ `try { … } catch (e) { emit(ErrorState()); }` in BLoC — try/catch belongs only in43 Infrastructure; BLoC receives `Either`, then folds44- ❌ `Left(Failure('Something went wrong'))` using a plain `String` — define typed `@freezed` Failure45 subclasses for each domain error46- ❌ `catch (e) {}` empty catch — always log and propagate; never swallow silently47- ❌ Throwing `Exception` from a repository — return `Left(Failure)` instead; exceptions must not48 cross the infrastructure boundary49- ❌ `catch (e) { print(e); }` — missing `AppLogger.error`; errors must be sent to Crashlytics with50 the original error and stack trace5152## Related Topics5354layer-based-clean-architecture | bloc-state-management5556---57> Source: [li-lance/android-seraphim-framework](https://github.com/li-lance/android-seraphim-framework) — distributed by [TomeVault](https://tomevault.io).58<!-- tomevault:4.0:skill_md:2026-06-16 -->
Run npx skillmds@latest add tomevault-io/li-lance-android-seraphim-framework-flutter-error-handling in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Error Handling It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.