pub trait AsyncForgeError:
StdError
+ Send
+ Sync
+ 'static {
// Required methods
fn kind(&self) -> &'static str;
fn caption(&self) -> &'static str;
fn async_handle<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn is_retryable(&self) -> bool { ... }
fn is_fatal(&self) -> bool { ... }
fn status_code(&self) -> u16 { ... }
fn exit_code(&self) -> i32 { ... }
fn user_message(&self) -> String { ... }
fn dev_message(&self) -> String { ... }
fn backtrace(&self) -> Option<&Backtrace> { ... }
fn register(&self) { ... }
}Expand description
An async-compatible version of the ForgeError trait.
This trait extends the standard error capabilities with async support, allowing for async error handling in futures and async functions.
§Example
Requires the async cargo feature (which pulls in async-trait).
The hidden #[cfg(feature = "async")] gate means this doctest is
only compiled when the feature is enabled — when running
cargo test --all-features it executes normally, and when the
feature is off it is silently skipped.
use error_forge::async_error::AsyncForgeError;
use async_trait::async_trait;
use std::error::Error as StdError;
#[derive(Debug)]
struct MyAsyncError { message: String }
impl std::fmt::Display for MyAsyncError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for MyAsyncError {}
#[async_trait]
impl AsyncForgeError for MyAsyncError {
fn kind(&self) -> &'static str { "AsyncExample" }
fn caption(&self) -> &'static str { "Async Example Error" }
async fn async_handle(&self) -> Result<(), Box<dyn StdError + Send + Sync>> {
Ok(())
}
}Required Methods§
Sourcefn async_handle<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn async_handle<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn StdError + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Async method to handle the error. This allows implementing custom async error handling logic.
Provided Methods§
Sourcefn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
Returns true if the operation can be retried
Sourcefn status_code(&self) -> u16
fn status_code(&self) -> u16
Returns an appropriate HTTP status code for the error
Sourcefn user_message(&self) -> String
fn user_message(&self) -> String
Returns a user-facing message that can be shown to end users
Sourcefn dev_message(&self) -> String
fn dev_message(&self) -> String
Returns a detailed technical message for developers/logs
Implementors§
impl AsyncForgeError for AppError
Provides async implementations for the AppError type.