android-error-handling
Skill18 starsChanged 4 months agoMITView on GitHub
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".
2 other projects use a version of this.
Adopted by
Most recently taken up by
- geertberkers/claude-skillsword for word, first seen Oct 11, 2026
- Shekhar23/claude-zero-to-hero-android-KMPword for word, first seen Mar 29, 2026
Other versions2 projects use a version of this.
Word for word · 2
- Shekhar23/claude-zero-to-hero-android-KMP★ 9100% same
- geertberkers/claude-skills★ 0100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository67 other files it gives its agents.
- agent-onboardingSkill
- android-backgroundSkill
- android-cliSkill
- android-compose-architectureSkill
- android-compose-componentsSkill
- android-data-layerSkill
- android-di-koinSkill
- android-integration-testingSkill
- android-jacoco-setupSkill
- android-jvm-test-coverageSkill
- android-module-structureSkill
- android-navigationSkill
- android-presentation-mviSkill
- android-preview-figma-verifySkill
- android-ui-screenshot-verifySkill
- android-ui-testingSkill
- android-ui-verifySkill
- android-unit-testingSkill
- android-version-catalogSkill
- architecture-decision-recordSkill
- careful-planningSkill
- compose-adaptive-layoutsSkill
- figma-to-android-vectorSkill
- finalizeSkill
- git-commitSkill
- handoffSkill
- kmp-compose-architectureSkill
- kmp-compose-componentsSkill
- kmp-data-layerSkill
- kmp-di-koinSkill
- kmp-error-handlingSkill
- kmp-integration-testingSkill
- kmp-migration-analyzerSkill
- kmp-module-structureSkill
- kmp-navigationSkill
- kmp-presentation-mviSkill
- kmp-ui-testingSkill
- kmp-unit-testingSkill
- kotlin-coroutinesSkill
- kotlin-flowsSkill
- kotlin-mutation-testingSkill
- openspec-artifact-review-lightSkill
- openspec-artifact-reviewSkill
- project-breakdownSkill
- react-data-layerSkill
- react-error-handlingSkill
- react-integration-testingSkill
- react-presentation-mviSkill
- react-project-structureSkill
- react-routingSkill
- react-screen-architectureSkill
- react-securitySkill
- react-server-stateSkill
- react-ui-componentsSkill
- react-unit-testingSkill
- speckit-parallelize-agent-teamsSkill
- speckit-parallelize-subagentsSkill
- spring-api-layerSkill
- spring-di-configurationSkill
- spring-integration-testingSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 69
All helpers return Result so they can be chained:
- Very specific: line 130
Never throw exceptions for expected failures — always return Result.Error.
- Very specific: line 145
Every error type that is displayed to the user should have a .toUiText() extension function.
- Very specific: line 150
If an error is purely internal and never shown to the user (e.g., a retry signal, an internal state marker), it does not need a .toUiText() …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.
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:
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:
repository.saveNote(note)
.onSuccess { /* update UI */ }
.onFailure { /* show error */ }
.asEmptyResult()Shared Error Types (core:domain)
DataError
sealed interface DataError : Error {
enum class Network : DataError {
BAD_REQUEST,
REQUEST_TIMEOUT,
UNAUTHORIZED,
FORBIDDEN,
NOT_FOUND,
CONFLICT,
TOO_MANY_REQUESTS,
NO_INTERNET,
PAYLOAD_TOO_LARGE,
SERVER_ERROR,
SERVICE_UNAVAILABLE,
SERIALIZATION,
UNKNOWN
}
enum class Local : DataError {
DISK_FULL,
NOT_FOUND,
UNKNOWN
}
}Feature-Specific Errors
Features define their own error types by implementing Error:
enum class PasswordValidationError : Error {
TOO_SHORT,
NO_UPPERCASE,
NO_DIGIT
}
// Used with Result — always a single error, not a list:
fun validatePassword(pw: String): EmptyResult<PasswordValidationError>Multiple validation errors are not supported — always return a single error type per Result.
Exception Handling Philosophy
Never throw exceptions for expected failures — always return Result.Error. Catch exceptions at the layer that is responsible for the exception:
| Exception origin | Catch in | Example |
| HTTP / network | Data layer | UnresolvedAddressException → DataError.Network.NO_INTERNET |
| Database / disk | Data layer | SQLiteFullException → DataError.Local.DISK_FULL |
| Business logic | Domain layer | Invalid input → Result.Error(ValidationError.TOO_SHORT) |
| Presentation | Presentation layer | Catch and map to Result.Error at that layer |
The layer that owns the exception catches it and converts it to a typed Result.Error. Upper layers never see raw exceptions for expected failures.
Mapping Errors to UiText
Every error type that is displayed to the user should have a .toUiText() extension function. Place it in:
- Feature's
presentationmodule — if the error is feature-specific (e.g.,AuthError.toUiText()) core:presentation— if the error is shared across features (e.g.,DataError.toUiText())
If an error is purely internal and never shown to the user (e.g., a retry signal, an internal state marker), it does not need a .toUiText() mapping.
// core:presentation
fun DataError.toUiText(): UiText {
return when (this) {
DataError.Network.NO_INTERNET -> UiText.StringResource(R.string.error_no_internet)
DataError.Network.SERVER_ERROR -> UiText.StringResource(R.string.error_server)
DataError.Network.UNAUTHORIZED -> UiText.StringResource(R.string.error_unauthorized)
DataError.Local.DISK_FULL -> UiText.StringResource(R.string.error_disk_full)
// ... map all user-facing cases
else -> UiText.StringResource(R.string.error_unknown)
}
}Safe Call Helpers (core:data)
Typed extension functions on HttpClient that wrap Ktor calls and map HTTP responses to Result<T, DataError.Network>:
suspend inline fun <reified Response : Any> HttpClient.get(
route: String,
queryParameters: Map<String, Any?> = mapOf()
): Result<Response, DataError.Network> {
return safeCall {
get {
url(constructRoute(route))
queryParameters.forEach { (key, value) ->
parameter(key, value)
}
}
}
}
suspend inline fun <reified Request, reified Response : Any> HttpClient.post(
route: String,
body: Request
): Result<Response, DataError.Network> {
return safeCall {
post {
url(constructRoute(route))
setBody(body)
}
}
}
suspend inline fun <reified Response : Any> HttpClient.delete(
route: String,
queryParameters: Map<String, Any?> = mapOf()
): Result<Response, DataError.Network> {
return safeCall {
delete {
url(constructRoute(route))
queryParameters.forEach { (key, value) ->
parameter(key, value)
}
}
}
}
suspend inline fun <reified T> safeCall(
execute: () -> HttpResponse
): Result<T, DataError.Network> {
val response = try {
execute()
} catch (e: UnresolvedAddressException) {
e.printStackTrace()
return Result.Error(DataError.Network.NO_INTERNET)
} catch (e: SerializationException) {
e.printStackTrace()
return Result.Error(DataError.Network.SERIALIZATION)
} catch (e: Exception) {
if (e is CancellationException) throw e
e.printStackTrace()
return Result.Error(DataError.Network.UNKNOWN)
}
return responseToResult(response)
}
suspend inline fun <reified T> responseToResult(
response: HttpResponse
): Result<T, DataError.Network> {
return when (response.status.value) {
in 200..299 -> Result.Success(response.body<T>())
401 -> Result.Error(DataError.Network.UNAUTHORIZED)
408 -> Result.Error(DataError.Network.REQUEST_TIMEOUT)
409 -> Result.Error(DataError.Network.CONFLICT)
413 -> Result.Error(DataError.Network.PAYLOAD_TOO_LARGE)
429 -> Result.Error(DataError.Network.TOO_MANY_REQUESTS)
in 500..599 -> Result.Error(DataError.Network.SERVER_ERROR)
else -> Result.Error(DataError.Network.UNKNOWN)
}
}
fun constructRoute(route: String): String {
return when {
route.contains(BuildConfig.BASE_URL) -> route
route.startsWith("/") -> BuildConfig.BASE_URL + route
else -> BuildConfig.BASE_URL + "/$route"
}
}Usage in a data source is clean and uniform:
suspend fun getNotes(): Result<List<NoteDto>, DataError.Network> {
return httpClient.get(route = "/notes")
}When to Use What
| Scenario | Error type | Example return |
| Network call | DataError.Network | Result<List<NoteDto>, DataError.Network> |
| Local DB access | DataError.Local | Result<Note, DataError.Local> |
| Repository (multi-source) | DataError (supertype) | Result<List<Note>, DataError> |
| Domain validation | Custom Error enum | EmptyResult<PasswordValidationError> |
| Auth logic | Custom Error enum | Result<User, AuthError> |
The Result wrapper is not limited to the data layer — use it anywhere a function has typed success and failure outcomes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

