1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 17:49:57 +01:00
effigenix/bin/.claude/skills/ddd-model/rules/error-handling.md
2026-02-18 23:25:12 +01:00

1.6 KiB

Error Handling in DDD

This document defines error handling principles that apply across all layers and languages.

Core Principles

  1. No Silent Failures - All errors must be explicitly handled or propagated
  2. Layer-Specific Errors - Each layer defines its own error types
  3. Error Transformation - Errors are transformed at layer boundaries
  4. Proper Logging - Original errors logged before transformation
  5. Result Types Over Exceptions - Prefer Result types (where supported) over exceptions

Language-Specific Implementation

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