Expand description
§nmbrs-errorhandler
Contract & axioms: SRD 07.
Modular composable error handler. Errors are classified by type name (regex) and routed through a chain of handlers that can log, count, meter, retry, or stop execution.
Designed for nmbrs’s op-dispatch loop, where every adapter op
result might be Ok or one of dozens of named error variants
— and operators want different policies for different error
families (retry timeouts, count + ignore WriteFailures,
stop on BadCredentials).
§Pieces
ErrorDetailis the structured error a producer hands in. Carries a name (used for routing), a retryable flag, and an optional result code.ErrorHandleris the trait every leaf handler implements (StopHandler,WarnHandler,RetryHandler,CounterHandler, …). Each one decides how to react to the incoming detail and may flipretryableorstopflags on it.ErrorRouterholds a list of(regex, handler chain)entries and dispatches each incoming detail to the first matching chain.
§Config syntax
Routes are declared as semicolon-separated pattern:chain
pairs. Inside a chain, , separates handler names:
"TimeoutError:retry,warn,counter;.*:stop"Reads as: a TimeoutError retries (and warns + counts on
each attempt); anything else stops the run.
use nmbrs_errorhandler::ErrorRouter;
let router = ErrorRouter::parse(
"TimeoutError:retry,warn,counter;.*:stop",
).expect("config parses");§Building details
ErrorDetail uses a builder-style API:
use nmbrs_errorhandler::ErrorDetail;
let d = ErrorDetail::retryable("TimeoutError")
.with_result_code(503);
assert!(d.is_retryable());
assert_eq!(d.name, "TimeoutError");§Defaults
For tests and one-line setups:
ErrorRouter::default_stop— stop on any error.ErrorRouter::default_warn_count— warn + count on any error, never stop. Convenient for diagnostic runs.
Modules§
- handlers
- Built-in error handler implementations.
Structs§
- Error
Detail - The error detail passed through and transformed by the handler chain.
- Error
Router - The error router: classifies errors and dispatches to handler chains.
Enums§
- Retry
- Whether an operation should be retried.
Traits§
- Error
Handler - A single error handler in the chain.