mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 21:19:58 +01:00
1.6 KiB
1.6 KiB
Error Handling in DDD
This document defines error handling principles that apply across all layers and languages.
Core Principles
- No Silent Failures - All errors must be explicitly handled or propagated
- Layer-Specific Errors - Each layer defines its own error types
- Error Transformation - Errors are transformed at layer boundaries
- Proper Logging - Original errors logged before transformation
- Result Types Over Exceptions - Prefer Result types (where supported) over exceptions
Language-Specific Implementation
- Java: See languages/java/error-handling.md
- Go: Use error returns and custom error types
Error Hierarchy
Domain Errors (business rule violations)
↓ transformed at boundary
Application Errors (use case failures)
↓ transformed at boundary
Infrastructure Errors (technical failures)
Logging Strategy
- ERROR: Infrastructure failures (database down, network error)
- WARN: Business rule violations (insufficient funds, invalid state)
- INFO: Normal operations (order placed, account created)
- DEBUG: Detailed flow information
- TRACE: Original errors when transforming between layers
Exception Boundary
Infrastructure Layer is the exception boundary:
- Infrastructure catches external exceptions (SQL, HTTP, etc.)
- Transforms to domain error types
- Logs original exception at ERROR level
- Returns domain error type
Domain and Application layers:
- Never throw exceptions (use Result types or errors)
- Only work with domain/application error types
- No try/catch blocks needed