result-pattern

Models success and failure in Kotlin layers using a custom Result type and sealed error hierarchies.

Updated Sep 12, 2026
One-click install
npx skills add https://github.com/Vierco/citoVisionApp --skill result-pattern-vierco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: result-pattern
Source: https://github.com/Vierco/citoVisionApp/tree/main/.claude/skills/result-pattern
Command: npx skills add https://github.com/Vierco/citoVisionApp --skill result-pattern-vierco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It standardizes how Kotlin Multiplatform applications handle expected failures across Domain, Application, and Infrastructure layers, replacing exception-based control flow with a typed Result<T, E> and sealed error classes. ## Core Features & Use Cases - Typed Error Modeling: Defines DomainError and AppError as sealed classes so every business failure is an explicit, closed case rather than a raw exception or string. - Layer-Safe Propagation: Infrastructure catches technical exceptions (network, database, serialization) and maps them to DomainError, while Application wraps DomainError inside AppError for UseCases. - Coroutines Safety: Enforces rethrowing CancellationException so cooperative cancellation is never broken by error handling. - Use Case: When designing a GetUserUseCase, define its signature as Result<User, AppError>, map repository failures with mapError, and consume the result in the ViewModel with fold to update UiState. ## Quick Start Ask the AI to define the signature and error types for a Repository or UseCase that can fail, following the Result pattern with DomainError and AppError.

Frequently Asked Questions about result-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors in Kotlin Clean Architecture without exceptions?▼

Define a custom sealed Result<T, E> type in a shared core module and return it from every Repository, UseCase, and DataSource function that can fail. Represent business errors as sealed DomainError or AppError subtypes instead of throwing exceptions.

Should I use kotlin.Result or a custom Result type in Kotlin?▼

Use a custom Result<T, E> type for public Domain, Application, and Infrastructure signatures. The stdlib kotlin.Result and runCatching lack a typed error channel, making it impossible to distinguish business failures from unexpected Throwables.

How do I map network exceptions to domain errors in a Repository?▼

Catch technical exceptions like IOException or SerializationException inside the Infrastructure implementation and return Result.Failure with the corresponding DomainError. Never let the original exception type escape the layer boundary.

Why must CancellationException be rethrown in coroutine error handling?▼

Catching CancellationException and converting it to a Failure breaks structured concurrency, preventing the coroutine from cancelling properly. Always rethrow it before handling other exception types in your catch blocks.

When should a Kotlin function throw an exception instead of returning Result?▼

Reserve exceptions for programming errors like unexpected nulls or broken contracts. Any expected business failure, such as user not found or invalid credentials, should be returned as Result.Failure with a typed error.