error-handling-patterns — Claude Code skill
This skill helps choose error-handling patterns such as exceptions, Result types, retries, and graceful degradation. Use it when building APIs or debugging failures.
/plugin marketplace add wshobson/agents
/plugin install developer-essentials@claude-code-workflowsWhat error-handling-patterns does
The skill covers exceptions, Result types, error codes, and Option/Maybe types. It helps classify recoverable failures such as timeouts and invalid input separately from unrecoverable faults such as memory exhaustion or programming bugs. It also addresses context, useful messages, logging, and resource cleanup.
The package includes core guidance, a Python order-processing example, and a pointer to deeper patterns in references/details.md. It also covers retry, circuit breakers, async and concurrent errors, and fault-tolerant distributed systems. The listed platforms are Claude Code, Codex, and Cursor.
Install it when an agent needs to design error boundaries or investigate application failures. For a small one-off check of a single try block, it is more than you need.
What it helps with
- design error handling for a new feature
- separate expected failures from fatal faults
- preserve context from an external service error
- review retry and circuit breaker logic
- write clearer messages for users and developers
Example prompts for the agent
- Design error handling for this API and choose between exceptions and Result types.
- Review `process_order` and find where errors are lost or logged twice.
- Suggest a retry and circuit breaker approach for these network failures.
How to install error-handling-patterns
1Plugin marketplace
/plugin marketplace add wshobson/agents/plugin install developer-essentials@claude-code-workflowsThis installs the whole developer-essentials plugin with all its skills
2Skills CLI (Vercel)
npx skills add wshobson/agents --skill error-handling-patterns -a claude-code3Manually: put the files in place
~/.claude/skills/error-handling-patterns/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/error-handling-patterns/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill error-handling-patterns -a codex2Manually: put the files in place
.agents/skills/error-handling-patterns/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill error-handling-patterns -a cursor2Manually: put the files in place
.cursor/skills/error-handling-patterns/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshobson/agents error-handling-patterns2Manually: put the files in place
.github/skills/error-handling-patterns/SKILL.mdPlatform CLI
gemini skills install https://github.com/wshobson/agents --path plugins/developer-essentials/skills/error-handling-patternsManually: put the files in place
.devin/skills/error-handling-patterns/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set213
The whole set →Similar
Questions about error-handling-patterns
How do I install error-handling-patterns in Claude Code?
Run npx skills add wshobson/agents --skill error-handling-patterns -a claude-code. The skill file will be placed at ~/.claude/skills/error-handling-patterns/SKILL.md.
What does error-handling-patterns do?
It guides agents through error-handling patterns for application code, APIs, and asynchronous flows. It also covers context preservation, logging, cleanup, and meaningful error messages.
Which platforms support this skill?
The skill is listed for Claude Code, Codex, and Cursor. Each platform has its own installation command in the source material.
Source text
SKILL.md · MIT
---
name: error-handling-patterns
description: Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.
---
# Error Handling Patterns
Build resilient applications with robust error handling strategies that gracefully handle failures and provide excellent debugging experiences.
## When to Use This Skill
- Implementing error handling in new features
- Designing error-resilient APIs
- Debugging production issues
- Improving application reliability
- Creating better error messages for users and developers
- Implementing retry and circuit breaker patterns
- Handling async/concurrent errors
- Building fault-tolerant distributed systems
## Core Concepts
### 1. Error Handling Philosophies
**Exceptions vs Result Types:**
- **Exceptions**: Traditional try-catch, disrupts control flow
- **Result Types**: Explicit success/failure, functional approach
- **Error Codes**: C-style, requires discipline
- **Option/Maybe Types**: For nullable values
**When to Use Each:**
- Exceptions: Unexpected errors, exceptional conditions
- Result Types: Expected errors, validation failures
- Panics/Crashes: Unrecoverable errors, programming bugs
### 2. Error Categories
**Recoverable Errors:**
- Network timeouts
- Missing files
- Invalid user input
- API rate limits
**Unrecoverable Errors:**
- Out of memory
- Stack overflow
- Programming bugs (null pointer, etc.)
## Detailed patterns and worked examples
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
## Best Practices
1. **Fail Fast**: Validate input early, fail quickly
2. **Preserve Context**: Include stack traces, metadata, timestamps
3. **Meaningful Messages**: Explain what happened and how to fix it
4. **Log Appropriately**: Error = log, expected failure = don't spam logs
5. **Handle at Right Level**: Catch where you can meaningfully handle
6. **Clean Up Resources**: Use try-finally, context managers, defer
7. **Don't Swallow Errors**: Log or re-throw, don't silently ignore
8. **Type-Safe Errors**: Use typed errors when possible
```python
# Good error handling example
def process_order(order_id: str) -> Order:
"""Process order with comprehensive error handling."""
try:
# Validate input
if not order_id:
raise ValidationError("Order ID is required")
# Fetch order
order = db.get_order(order_id)
if not order:
raise NotFoundError("Order", order_id)
# Process payment
try:
payment_result = payment_service.charge(order.total)
except PaymentServiceError as e:
# Log and wrap external service error
logger.error(f"Payment failed for order {order_id}: {e}")
raise ExternalServiceError(
f"Payment processing failed",
service="payment_service",
details={"order_id": order_id, "amount": order.total}
) from e
# Update order
order.status = "completed"
order.payment_id = payment_result.id
db.save(order)
return order
except ApplicationError:
# Re-raise known application errors
raise
except Exception as e:
# Log unexpected errors
logger.exception(f"Unexpected error processing order {order_id}")
raise ApplicationError(
"Order processing failed",
code="INTERNAL_ERROR"
) from e
```
## Common Pitfalls
- **Catching Too Broadly**: `except Exception` hides bugs
- **Empty Catch Blocks**: Silently swallowing errors
- **Logging and Re-throwing**: Creates duplicate log entries
- **Not Cleaning Up**: Forgetting to close files, connections
- **Poor Error Messages**: "Error occurred" is not helpful
- **Returning Error Codes**: Use exceptions or Result types
- **Ignoring Async Errors**: Unhandled promise rejections
© Seth Hobson · MIT · wshobson/agents