Skip to main content

Module error_sink

Module error_sink 

Expand description

A reusable sink for errors that occur in fire-and-forget contexts.

Some work in rama cannot return its error to a caller — e.g. a spawned HTTP upgrade handler or a background relay task. The error still matters (it should at least be observable), but there is no Result left to bubble it up through. ErrorSink is the shared abstraction for handing such an error somewhere useful, so each call site does not reinvent its own ad-hoc logging or routing.

The provided TracingErrorSink emits the error via tracing at a configurable level (DEBUG by default), and is what rama components fall back to when no custom sink is configured. Any Fn(E) + Send + Sync + 'static is also an ErrorSink, so a closure can be used for custom routing (metrics, a channel, …).

§Example

use rama_core::error::{BoxError, BoxErrorExt as _};
use rama_core::error_sink::{ErrorSink, TracingErrorSink};

// the default sink traces at DEBUG level
let sink = TracingErrorSink::default();
sink.sink_error(BoxError::from_static_str("something went wrong"));

// a closure is a sink too
let sink = |err: BoxError| eprintln!("custom: {err}");
sink.sink_error(BoxError::from_static_str("boom"));

Structs§

DropErrorSink
An ErrorSink that silently drops every error, for any error type E.
TracingErrorSink
An ErrorSink that emits errors via tracing at a configurable level.

Traits§

ErrorSink
A sink for errors produced in fire-and-forget contexts where the error cannot be propagated back to a caller.