Skip to main content

ErrorRouter

Struct ErrorRouter 

Source
pub struct ErrorRouter { /* private fields */ }
Expand description

The error router: classifies errors and dispatches to handler chains.

§Config Syntax

"TimeoutError:retry,warn,counter;.*:stop"
  • Error patterns (left of :) are regex matched against the error name
  • Handler names (right of :) are comma-separated, executed in chain order
  • Multiple rules are semicolon-separated
  • If no pattern prefix, .* (match all) is assumed

§Example

use nmbrs_errorhandler::ErrorRouter;

let router = ErrorRouter::parse("TimeoutError:retry,warn;.*:counter,stop").unwrap();

Implementations§

Source§

impl ErrorRouter

Source

pub fn parse(spec: &str) -> Result<Self, String>

Parse a config spec into a router.

Source

pub fn retry_verb_budget(&self) -> Option<u32>

The retry budget implied by the spec’s retry / retry(N) verbs; None when no rule carries a retry verb. See the field doc.

Source

pub fn has_catch_all(&self) -> bool

True when some rule carries the literal match-all pattern .* (written explicitly, or implied by a pattern-less rule). An error class matching NO rule falls through to stop with only an eprintln — a router without a catch-all therefore has a silent fall-through mode, which workload-load linting warns about. This checks the pattern SOURCE, not regex universality: .* is the one canonical way to write the catch-all.

Source

pub fn default_stop() -> Self

Create a simple router with a default handler for all errors.

Source

pub fn default_warn_count() -> Self

Create a router that warns and counts all errors.

Source

pub fn handle_error( &self, error_name: &str, error_msg: &str, cycle: u64, duration_nanos: u64, ) -> ErrorDetail

Handle an error: classify by name, dispatch through the matching handler chain, return the final ErrorDetail.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.