arrow-typed-errors
Original:🇺🇸 English
Translated
Kotlin + Arrow typed error handling using Raise DSL and wrapper types (Either/Option/Ior/Result/nullable), including validation with accumulation, interop with exceptions, and custom error wrappers. Use for designing or refactoring error modeling, converting exception-based flows, building smart constructors, accumulating validation errors, or integrating Outcome/Progress-style wrappers with Arrow.
1installs
Sourcealexandru/skills
Added on
NPX Install
npx skill4agent add alexandru/skills arrow-typed-errorsTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Arrow Typed Errors (Kotlin)
Quick start
- Classify the failure first: logical failure (typed error) vs exceptional failure (exception).
- Pick the surface type:
- + builder (
Raise<E>/either {}/option {}) for composable logic.nullable {} - Wrapper type (/
Either/Option/Ior/nullable) for API boundaries.Result
- Read for API details and patterns before coding if unsure.
references/typed-errors.md
Workflow
- Model errors as sealed types.
- Implement happy-path logic with Raise DSL (prefer or
either {}depending on output).nullable {} - Guard invariants with /
ensure.ensureNotNull - Interop with external code:
- Use /
catchto convert expected exceptions into typed errors.Either.catchOrThrow
- Use
- Compose with and transform errors with
.bind()orwithError.recover - For validation across fields or lists, use accumulation (,
zipOrAccumulate, ormapOrAccumulate).accumulate - Expose wrapper types at module boundaries; keep Raise internally when possible.
Patterns to apply
- Smart constructors (parse, don't validate): make constructors private; expose returning
invoke.Either - Validation accumulation: use and
EitherNel/zipOrAccumulate.mapOrAccumulate - Wrapper choice:
- Prefer nullable for optional values unless nested nullability issues exist; then use .
Option - Use for disjoint success/failure;
Eitheronly when success + warning is meaningful.Ior - Use only when errors are
Resultand interop with stdlib APIs is required.Throwable
- Prefer nullable for optional values unless nested nullability issues exist; then use
- Error translation across layers: use to map inner errors to outer domain errors.
withError - Drop error types explicitly: wrap with
bindwhen moving from informative error types toignoreErrors/nullable flows.Option - Avoid sealed-on-sealed inheritance: model error hierarchies with composition (wrapper data classes), not sealed inheritance chains.
References
- Load for API details, error accumulation, wrapper-specific guidance, and sample snippets.
references/typed-errors.md