error-handling-patterns
Helps developers implement robust error handling strategies and fault-tolerant system designs.
Install
mkdir -p .claude/skills/error-handling-patterns && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/51" && unzip -o skill.zip -d .claude/skills/error-handling-patterns && rm skill.zipInstalls to .claude/skills/error-handling-patterns
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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.Key capabilities
- →Categorize errors into recoverable vs. unrecoverable types
- →Choose between exceptions, Result types, and error codes
- →Apply fail-fast validation logic
- →Implement structured logging strategies
- →Execute try-finally or defer blocks for resource cleanup
How it works
Analyzes control flow to suggest architectural changes for error propagation and resource management based on a set of predefined resiliency principles.
Inputs & outputs
When to use error-handling-patterns
- →Designing fault-tolerant APIs
- →Implementing retry logic
- →Improving production debugging
- →Handling async/concurrent errors
About this skill
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
- Fail Fast: Validate input early, fail quickly
- Preserve Context: Include stack traces, metadata, timestamps
- Meaningful Messages: Explain what happened and how to fix it
- Log Appropriately: Error = log, expected failure = don't spam logs
- Handle at Right Level: Catch where you can meaningfully handle
- Clean Up Resources: Use try-finally, context managers, defer
- Don't Swallow Errors: Log or re-throw, don't silently ignore
- Type-Safe Errors: Use typed errors when possible
# 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 Exceptionhides 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
When not to use it
- →Replacing standard language-specific error handling libraries
- →Debugging hardware-level failures or kernel panics
- →Managing complex transaction rollbacks in relational databases
Limitations
- →Cannot fix logic bugs that cause unexpected behavior
- →Requires manual integration of patterns into existing codebase
- →Does not automatically setup monitoring or alerting systems
How it compares
It maps specific failure scenarios to theoretical patterns rather than just suppressing or logging exceptions blindly.
Compared to similar skills
error-handling-patterns side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| error-handling-patterns (this skill) | 35 | 2mo | No flags | Intermediate |
| codebase-context-extractor | 4 | 9mo | Review | Intermediate |
| investigating-code-patterns | 1 | 8mo | No flags | Beginner |
| investigate | 1 | 6mo | Review | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by wshobson
View all by wshobson →You might also like
codebase-context-extractor
lofcz
This skill provides a comprehensive context extraction system for large codebases. It intelligently analyzes code structure, dependencies, and relationships to extract relevant context for understanding, debugging, or modifying code.
investigating-code-patterns
CaptainCrouton89
Systematically trace code flows, locate implementations, diagnose performance issues, and map system architecture. Use when understanding how existing systems work, researching concepts, exploring code structure, or answering "how/where/why is X implemented?" questions.
investigate
MadAppGang
Unified entry point for code investigation. Auto-routes to specialized detective based on query keywords. Use when investigation type is unclear or for general exploration.
codex-review
rymetry
|
connector-librarian
frvnkfrmchicago
>
claude
yuiseki
|