Skip to main content

AsyncForgeError

Trait AsyncForgeError 

Source
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§

Source

fn kind(&self) -> &'static str

Returns the kind of error, typically matching the enum variant

Source

fn caption(&self) -> &'static str

Returns a human-readable caption for the error

Source

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§

Source

fn is_retryable(&self) -> bool

Returns true if the operation can be retried

Source

fn is_fatal(&self) -> bool

Returns true if the error is fatal and should terminate the program

Source

fn status_code(&self) -> u16

Returns an appropriate HTTP status code for the error

Source

fn exit_code(&self) -> i32

Returns an appropriate process exit code for the error

Source

fn user_message(&self) -> String

Returns a user-facing message that can be shown to end users

Source

fn dev_message(&self) -> String

Returns a detailed technical message for developers/logs

Source

fn backtrace(&self) -> Option<&Backtrace>

Returns a backtrace if available

Source

fn register(&self)

Registers the error with the central error registry

Implementors§

Source§

impl AsyncForgeError for AppError

Provides async implementations for the AppError type.