Derive Macro ModError

Source
#[derive(ModError)]
{
    // Attributes available to this derive:
    #[error_prefix]
    #[error_display]
    #[error_kind]
    #[error_caption]
    #[error_retryable]
    #[error_http_status]
    #[error_exit_code]
}
Expand description

Derive macro for ModError

This macro automatically implements the ForgeError trait and common error handling functionality for a struct or enum, allowing for “lazy mode” error creation with minimal boilerplate.

§Example

When the macro is used in your application where error-forge is a dependency:

use error_forge::ModError;
 
#[derive(Debug, ModError)]
#[error_prefix("Database")]
pub enum DbError {
    #[error_display("Connection to {0} failed")]
    ConnectionFailed(String),
 
    #[error_display("Query execution failed: {reason}")]
    QueryFailed { reason: String },
 
    #[error_display("Transaction error")]
    #[error_http_status(400)]
    TransactionError,
}

Note: This is a procedural macro that is re-exported by the error-forge crate. When using in your application, import it from the main crate with use error_forge::ModError;.