android-error-handlinglisted
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