error-handling-patterns

Design context-specific error handling patterns for backend code and APIs.

14|1|Updated Oct 23, 2025
One-click install
npx skills add https://github.com/marcioaltoe/claude-craftkit --skill error-handling-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling-patterns
Source: https://github.com/marcioaltoe/claude-craftkit/tree/main/plugins/architecture-design/skills/error-handling-patterns
Command: npx skills add https://github.com/marcioaltoe/claude-craftkit --skill error-handling-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive guidance on implementing robust and maintainable error handling. It helps developers choose the right strategy (exceptions vs. Result pattern), provide rich error context, and implement recovery mechanisms like retries and circuit breakers, leading to more resilient applications.

Core Features & Use Cases

  • Exceptions vs. Result Pattern: Guides on when to use exceptions for unexpected errors and the Result pattern for expected business failures.
  • Custom Exception Hierarchy: Defines domain-specific and infrastructure-specific custom error classes with rich context.
  • Validation Strategies: Emphasizes input validation at system boundaries (e.g., with Zod) and domain validation within entities.
  • Error Recovery: Implements retry logic, circuit breakers, and fallback values for transient failures and external service dependencies.
  • Use Case: "Implement the Result pattern for a findByEmail operation in my UserService to gracefully handle 'user not found' scenarios without throwing exceptions."

Quick Start

Refactor a function to use custom exceptions with rich context instead of generic Error objects.

Frequently Asked Questions about error-handling-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between exceptions and the Result pattern for error handling?

Exceptions handle unexpected errors that break normal flow; the Result pattern handles expected business failures like validation or 'user not found' without throwing. Use exceptions for truly exceptional conditions and Result pattern for anticipated domain-level failures.

What's the best way to implement custom exception hierarchies in backend code?

Define domain-specific and infrastructure-specific exception classes per bounded context instead of base error classes. Include rich context data—error codes, details, and domain state—so handlers can recover or log precisely without guessing what failed.

How do I validate user input at system boundaries in APIs?

Validate at entry points using tools like Zod to catch malformed data before it enters your domain. Separate input validation from domain validation; domain validation happens within entities and enforces business rules after structure is verified.

How can I make external service calls resilient with retries and circuit breakers?

Retry logic handles transient failures by attempting requests again with backoff. Circuit breakers stop sending requests when services fail repeatedly, failing fast and protecting downstream systems from cascading failures.

Can I apply error handling patterns across different architecture layers and frameworks?

Yes. Use context-specific error types in repositories, use cases, and controllers. Clean Architecture and dependency injection containers isolate error handling per layer so each layer throws or catches appropriate exceptions for its responsibility.

Why should I avoid generic Error objects and return codes in error handling?

Generic errors lose context needed for recovery; return codes require callers to know magic numbers. Rich custom exceptions with context data and clear semantics let handlers make better decisions and enable better logging and monitoring.