← ClaudeAtlas

android-error-handlinglisted

Generic Result wrapper, error types, and extension helpers for Android/KMP - Result<T, E>, DataError, EmptyResult, map, onSuccess, onFailure. Use this skill whenever defining error types, creating a Result wrapper, handling success/failure flows, mapping errors, or working with typed errors anywhere in the app (not just data layer — also validation, auth, domain logic). Trigger on phrases like "Result wrapper", "error handling", "DataError", "onSuccess", "onFailure", "EmptyResult", "map result", "error type", "validation error", or "typed errors".
lenorebreakneck630/claude-zero-to-hero-android-KMP · ★ 1 · AI & Automation · score 64
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android / KMP Error Handling ## Result Wrapper (`core:domain`) A generic, typed Result that works across all layers — data, domain, presentation, validation, anywhere a function can succeed or fail with a typed error. ```kotlin interface Error sealed interface Result<out D, out E : Error> { data class Success<out D>(val data: D) : Result<D, Nothing> data class Error<out E : com.example.Error>(val error: E) : Result<Nothing, E> } typealias EmptyResult<E> = Result<Unit, E> ``` --- ## Extension Helpers (`core:domain`) These live alongside the `Result` definition: ```kotlin inline fun <T, E : Error, R> Result<T, E>.map( map: (T) -> R ): Result<R, E> { return when (this) { is Result.Error -> Result.Error(error) is Result.Success -> Result.Success(map(this.data)) } } inline fun <T, E : Error> Result<T, E>.onSuccess( action: (T) -> Unit ): Result<T, E> { return when (this) { is Result.Error -> this is Result.Success -> { action(this.data) this } } } inline fun <T, E : Error> Result<T, E>.onFailure( action: (E) -> Unit ): Result<T, E> { return when (this) { is Result.Error -> { action(error) this } is Result.Success -> this } } fun <T, E : Error> Result<T, E>.asEmptyResult(): EmptyResult<E> { return map { } } ``` All helpers return `Result` so they can be chained: ```kotlin repository.saveNote(note) .onSucce