Module async_ext

Module async_ext 

Source
Expand description

Async extensions for error handling (requires async feature) Async extensions for error-rail.

This module provides async-aware error handling utilities that maintain the same lazy attachment philosophy as the sync counterparts.

Note: lazy string formatting is provided by context! / .with_ctx(...). Passing an already-formatted String (e.g. format!(...)) is eager.

§Feature Flag

Requires the async feature to be enabled:

[dependencies]
error-rail = { version = "0.8", features = ["async"] }

§Examples

use error_rail::prelude_async::*;

#[derive(Debug)]
struct User;

#[derive(Debug)]
struct ApiError;

async fn fetch_from_db(_id: u64) -> Result<User, ApiError> {
    Err(ApiError)
}

async fn fetch_user(id: u64) -> BoxedResult<User, ApiError> {
    fetch_from_db(id)
        .ctx("fetching user from database")
        .await
        .map_err(Box::new)
}

Structs§

AsyncErrorPipeline
Async error pipeline for chainable error handling.
ContextFuture
A Future wrapper that attaches error context lazily.
ExponentialBackoff
Exponential backoff retry policy.
FixedDelay
Fixed delay retry policy.
RetryResult
Result of a retry operation with metadata about attempts.
SpanContextFuture
Future wrapper that captures span context on error.
TimeoutError
Error type representing a timeout.

Enums§

TimeoutResult
Result type for timeout operations that can fail with either the inner error or a timeout.

Traits§

FutureResultExt
Extension trait for attaching error context to async Result-returning futures.
FutureSpanExt
Extension trait for futures that adds tracing span context to errors.
ResultSpanExt
Extension trait for Result types to add span context to errors.
RetryPolicy
Defines a retry policy for async operations.

Functions§

instrument_error
Instruments an error with the current span and all its parents.
retry_transient
Retries an async operation using Tokio’s sleep, returning a boxed error.
retry_transient_n
Retries an async operation with a simple count limit using Tokio’s sleep.
retry_transient_unboxed
Retries an async operation using Tokio’s sleep, returning an unboxed error.
retry_with_metadata
Retries an operation with detailed result metadata.
retry_with_policy
Retries an async operation according to a policy when transient errors occur.
try_with_timeout
Executes an async operation with a timeout, returning a TimeoutResult.
validate_all_async
Runs multiple async validations sequentially and collects all errors.
validate_seq_async
Runs async validations sequentially, where each validation depends on the previous result.