Provides robust error handling strategies and patterns. Use when the user mentions resilience, error handling, fallbacks, or debugging failures.
Prevent cascading failures by rejecting requests when a service is failing.
# Logic: CLOSED -> failure threshold reached -> OPEN (wait timeout) -> HALF_OPEN (test)
Collect multiple errors (e.g., during validation) instead of failing on the first one.
class ErrorCollector {
private errors: Error[] = [];
add(error: Error) { this.errors.push(error); }
throw() { if (this.errors.length) throw new AggregateError(this.errors); }
}
Provide fallback functionality (e.g., fetch from cache if DB is down).
def with_fallback(primary, fallback):
try: return primary()
except Exception: return fallback()
ApplicationError(Exception) as a base.@contextmanager or try/finally.type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }.catch.Result<T, E> and the ? operator.if err != nil explicitly; use fmt.Errorf("...: %w", err) for wrapping.