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§
- Async
Error Pipeline - Async error pipeline for chainable error handling.
- Context
Future - A Future wrapper that attaches error context lazily.
- Exponential
Backoff - Exponential backoff retry policy.
- Fixed
Delay - Fixed delay retry policy.
- Retry
Result - Result of a retry operation with metadata about attempts.
- Span
Context Future - Future wrapper that captures span context on error.
- Timeout
Error - Error type representing a timeout.
Enums§
- Timeout
Result - Result type for timeout operations that can fail with either the inner error or a timeout.
Traits§
- Future
Result Ext - Extension trait for attaching error context to async Result-returning futures.
- Future
Span Ext - Extension trait for futures that adds tracing span context to errors.
- Result
Span Ext - Extension trait for
Resulttypes to add span context to errors. - Retry
Policy - 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.