Skip to main content

nmbrs_errorhandler/
handler.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! ErrorHandler trait: the composable unit in the handler chain.
5
6use crate::detail::ErrorDetail;
7
8/// A single error handler in the chain.
9///
10/// Each handler can:
11/// - Perform side effects (logging, counting, metering)
12/// - Transform the `ErrorDetail` (mark as retryable, change result code)
13/// - Halt execution (by panicking or returning a stop signal)
14///
15/// Handlers are composable: the chain passes `ErrorDetail` through
16/// each handler in sequence.
17pub trait ErrorHandler: Send + Sync {
18    /// Handle an error, returning a potentially transformed ErrorDetail.
19    ///
20    /// - `name`: error classification name (type name or custom)
21    /// - `error_msg`: the error message
22    /// - `cycle`: the cycle number that was executing
23    /// - `duration_nanos`: how long into the operation the error occurred
24    /// - `detail`: the current ErrorDetail from upstream handlers
25    fn handle(
26        &self,
27        name: &str,
28        error_msg: &str,
29        cycle: u64,
30        duration_nanos: u64,
31        detail: ErrorDetail,
32    ) -> ErrorDetail;
33}