Skip to main content

Crate nmbrs_errorhandler

Crate nmbrs_errorhandler 

Source
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

  • ErrorDetail is the structured error a producer hands in. Carries a name (used for routing), a retryable flag, and an optional result code.
  • ErrorHandler is the trait every leaf handler implements (StopHandler, WarnHandler, RetryHandler, CounterHandler, …). Each one decides how to react to the incoming detail and may flip retryable or stop flags on it.
  • ErrorRouter holds 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:

Modules§

handlers
Built-in error handler implementations.

Structs§

ErrorDetail
The error detail passed through and transformed by the handler chain.
ErrorRouter
The error router: classifies errors and dispatches to handler chains.

Enums§

Retry
Whether an operation should be retried.

Traits§

ErrorHandler
A single error handler in the chain.