Error handling patterns including exceptions, Result pattern, validation strategies, retry logic, and circuit breakers. **ALWAYS use when implementing error handling in backend code, APIs, use cases, or validation logic.** Use proactively for robust error handling, recovery mechanisms, and failure scenarios. Examples - "handle errors", "Result pattern", "throw exception", "validate input", "error recovery", "retry logic", "circuit breaker", "exception hierarchy".
View on GitHubmarcioaltoe/claude-craftkit
architecture-design
plugins/architecture-design/skills/error-handling-patterns/SKILL.md
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/marcioaltoe/claude-craftkit/blob/main/plugins/architecture-design/skills/error-handling-patterns/SKILL.md -a claude-code --skill error-handling-patternsInstallation paths:
.claude/skills/error-handling-patterns/You are an expert in error handling patterns and strategies. You guide developers to implement robust, maintainable error handling that provides clear feedback and proper recovery mechanisms.
**For complete backend implementation examples using these error handling patterns (Clean Architecture layers, DI Container, Use Cases, Repositories), see `backend-engineer` skill**
## When to Engage
You should proactively assist when:
- Implementing error handling within bounded contexts
- Designing context-specific validation logic
- Creating context-specific exception types (no base classes)
- Implementing retry or recovery mechanisms per context
- User asks about error handling strategies
- Reviewing error handling without over-abstraction
## Modular Monolith Error Handling
### Context-Specific Errors (No Base Classes)
```typescript
// ❌ BAD: Base error class creates coupling
export abstract class DomainError extends Error {
// Forces all contexts to use same error structure
}
// ✅ GOOD: Each context has its own errors
// contexts/auth/domain/errors/auth-validation.error.ts
export class AuthValidationError extends Error {
constructor(message: string, public readonly field?: string) {
super(message);
this.name = "AuthValidationError";
}
}
// contexts/tax/domain/errors/tax-calculation.error.ts
export class TaxCalculationError extends Error {
constructor(message: string, public readonly ncmCode?: string) {
super(message);
this.name = "TaxCalculationError";
}
}
```
### Error Handling Rules
1. **Each context owns its errors** - No shared error classes
2. **Duplicate error structures** - Better than coupling through inheritance
3. **Context-specific metadata** - Each error has relevant context data
4. **Simple over clever** - Avoid complex error hierarchies
## Core Principles
### 1. Use Exceptions, Not Return Codes
```typescript
// ✅ Good - Use exceptions with context
export class CreateUserUseCase {
async execute(dto: CreateUserDto): Pro