Skill
handling-errors-with-either
Apply when creating, refactoring, changing, planning (plan mode) or reviewing any code that uses Arrow's Either type for error handling. This includes adding, modifying, or fixing Either return types, sealed error classes, either {} builders, .bind() calls, fold() mappings, or Left/Right handling in any part of the code.
From kotlin-cross-cuttingInstall
1
Run in your terminal$
npx claudepluginhub allousas/claude-code-plugins --plugin kotlin-cross-cuttingTool Access
This skill uses the workspace's default tool permissions.
Supporting Assets
View in Repositoryexamples.mdSkill Content
Purpose
Use Arrow's Either<Error, Success> as an alternative to exceptions for domain error handling. Errors become explicit return values, making failure paths visible in function signatures and avoiding exception-based control flow.
Strategy
- Domain functions return
Either<DomainError, Result>instead of throwing exceptions - Application services use
either {}builder with.bind()to compose operations - Controllers unwrap Either results and map to HTTP responses
- Infrastructure failures (DB, HTTP client) still use exceptions - Either is only for domain errors
Guidelines
DO:
- Use sealed classes/interfaces for error types (e.g.,
sealed interface CreateTeamError) - Use Arrow's
either {}builder in application services to compose multiple Either-returning operations - Use
.bind()insideeither {}to short-circuit on errors (replaces flatMap chains) - Keep error types specific to each domain function (e.g.,
CreateTeamError,AddMemberError), add enums/strings inside for more granular information - Map Either results to HTTP responses in controllers using
fold()orwhen - Use
Either.Leftfor domain errors,Either.Rightfor success
DON'T:
- NEVER return generic Domain errors from domain functions or application services, use specific ones
- Chain
.map,.flatMap,.onRight- useeither {}builder instead for readability - Return Either from infrastructure functions - use exception-based error handling instead
- Use Either for infrastructure failures - those should remain as exceptions
- Create a single global error type for all use cases - keep error types scoped
Spring specifics
- Controllers map
Either.Leftto appropriate HTTP error responses GlobalExceptionHandlerstill handles infrastructure exceptions
Examples
Please use always these examples as reference: examples.md
Similar Skills
Stats
Parent Repo Stars1
Parent Repo Forks0
Last CommitFeb 25, 2026