agentleFS
smileynetsmileynet/code-spice/skills/error-handling-patterns/SKILL.md

error-handling-patterns

Skill0 starsChanged 9 months agoMITView on GitHub

Error handling strategy selection, recoverability analysis, and signaling techniques. Use when choosing between exceptions, result types, error codes, or other error handling approaches, designing error-handling APIs, wrapping third-party library errors, or evaluating whether errors should be explicit or implicit.

23 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use 0-template, github-actions-builder and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • JayRHaSkill

    0-template

    Template for creating a new Agent Skill. Copy this folder, rename it to your skill's kebab-case name, and fill in every section. Use this as the starting point whenever you author a new skill for the AgentSkills library.

    Also in 3 projects that use this

  • JayRHaSkill

    github-actions-builder

    Builds reliable, fast, and secure GitHub Actions CI/CD workflows with dependency caching, build matrices, scoped secrets, concurrency control, and reusable/composite workflows. Use this skill when the user asks to "create a GitHub Actions workflow", "set up CI", "add CI/CD", "fix a flaky/slow GitHub Actions pipeline", "add a build matrix", "cache dependencies in CI", "write a reusable workflow", "configure deployment with environments and secrets", or mentions files under .github/workflows.

    Also in 3 projects that use this

  • xmqywxSkill

    meeting-summarizer

    Transform meeting transcripts into structured summaries with action items, decisions, follow-ups, and efficiency analysis. Works with any meeting format.

    Also in 3 projects that use this

  • MehdibargachSkill

    okr-writer

    Turn business goals into structured OKRs with measurable Key Results, linked initiatives, alignment check, and anti-goals. Takes a strategic priority and outputs ready-to-use OKRs.

    Also in 3 projects that use this

  • pbc-osSkill

    secrets-manager

    Set up and configure cloud secrets management for your AI agent. Guides users through platform selection (GCP, AWS, Azure, 1Password, Doppler, HashiCorp Vault), account setup, CLI configuration, and secure credential storage.

    Also in 3 projects that use this

  • +7 more from JayRHa

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before shipping error handling code:

    line 71

“Common” is measured: kept by at least 6 in 10 of the 23 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Error Handling Patterns

Error Strategy Decision Table

SituationStrategyWhy
Invalid user inputValidate and return descriptive errorUser can fix it; fail fast at boundary
Programming error (bug)Crash / unchecked exceptionDon't mask bugs; fix them
External system failureRetry with backoff or circuit-breakTransient failures resolve; permanent ones need escalation
Expected business case (not found)Return empty/Optional/ResultNot an error — it's a valid outcome
Security violationLog, deny, alertDon't reveal details to caller
Resource exhaustion (OOM, disk)Fail fast with clear messageCan't recover; make the failure diagnosable

Recoverability Framework

Can the caller realistically recover?
├── Yes → Use explicit signaling (Result type, checked exception)
│   ├── Expected failure (not found, validation) → Return type encodes the failure
│   └── Transient failure (timeout, rate limit) → Retry with backoff
├── No → Let it propagate (unchecked exception, panic)
│   ├── Bug → Crash and fix the code
│   └── Infrastructure failure → Propagate to top-level handler
└── Caller determines → Provide both options (Result + throw helper)

Signaling Comparison Table

TechniqueExplicit?Composable?PerformanceBest For
Checked exceptionsYes (compiler-enforced)NoModeratePublic APIs, Java
Unchecked exceptionsNo (caller may miss)NoModerateBugs, unrecoverable
Result/Either typesYes (type-enforced)Yes (map/flatMap)Low overheadFunctional style, Rust/Kotlin
Optional/NullablePartialPartialLow overhead"Not found" cases only
Error codesNo (easy to ignore)NoMinimalLow-level, C interop, hot paths

Error-Hiding Antipatterns

AntipatternSymptomSeverityFix
Empty catch blockcatch (e) {} — error vanishesCriticalHandle, log, or propagate
Swallow and return nullcatch → return null hides root causeCriticalDistinguish "not found" from "system error"
Log and continueError logged but execution continues in broken stateWarningDecide: recover meaningfully or propagate
Generic catch-allcatch (Exception e) masks different failure modesWarningCatch specific exceptions; let unexpected ones propagate
Error as magic valueReturn -1 or "" to signal failureWarningUse typed error channels (Result, Optional, exceptions)
Exception wrapping without contextthrow new RuntimeException(e)NoteAdd domain context: throw new PaymentFailedException("charge declined", e)

Strategy Selection Flowchart

What kind of code are you writing?
├── Public API / library
│   ├── Caller must handle → Checked exception or Result type
│   └── Caller can't handle → Unchecked exception (document it)
├── Internal service code
│   ├── Expected failure → Result type
│   └── Bug / unexpected → Let it propagate
├── Hot path (measured)
│   └── Error codes or Result types (avoid exception overhead)
└── Script / CLI
    └── Crash with clear message (fail fast)

Checklist

Before shipping error handling code:

  • Every catch block either recovers, propagates, or fails explicitly
  • No empty catch blocks
  • "Not found" and "system failure" use different error channels
  • Error messages are actionable (what happened, what to do)
  • Third-party exceptions wrapped in domain types at boundaries
  • Error paths have test coverage

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.