Crate error_forge

Source
Expand description

§Error Forge

A high-performance, flexible Rust error framework for defining, formatting, chaining, and managing rich custom errors across large-scale applications.

§Overview

Error Forge provides a comprehensive solution for error handling in Rust applications, focusing on performance, flexibility, and developer ergonomics. It enables defining structured error types with minimal boilerplate, making error handling more efficient and maintainable.

§Key Features

  • define_errors! macro - Create rich error enums with minimal boilerplate
  • #[derive(ModError)] proc-macro - “Lazy mode” errors with attribute-based configuration
  • group! macro - Compose multi-error enums with automatic From conversions
  • Console theming - ANSI-colored errors for CLI applications
  • Built-in panic hook - Enhanced panic formatting
  • ForgeError trait - Unified interface for error handling
  • Serialization support - Optional serde integration

§Quick Start

use error_forge::{define_errors, ForgeError};
 
// Define our error type
define_errors! {
    #[derive(Debug)]
    pub enum AppError {
        #[error(display = "Configuration error: {message}")]
        #[kind(Config, retryable = false, status = 500)]
        Config { message: String },
         
        #[error(display = "Database error: {message}")]
        #[kind(Database, retryable = true, status = 503)]
        Database { message: String },
    }
}

// Use the error type
fn main() -> Result<(), error_forge::AppError> {
    if cfg!(debug_assertions) {
        return Err(error_forge::AppError::config("Missing configuration"));
    }
    Ok(())
}

§Enhanced Error Reporting

// Import the predefined AppError type from the library
use error_forge::{console_theme::print_error, AppError};

let error = AppError::config("Database connection failed");
print_error(&error);  // Displays a nicely formatted error message

Re-exports§

pub use crate::error::ForgeError;
pub use crate::error::Result;
pub use crate::error::AppError;
pub use crate::console_theme::ConsoleTheme;
pub use crate::console_theme::print_error;
pub use crate::console_theme::install_panic_hook;
pub use crate::context::ContextError;
pub use crate::context::ResultExt;
pub use crate::registry::WithErrorCode;
pub use crate::registry::CodedError;
pub use crate::registry::register_error_code;
pub use crate::registry::ErrorRegistry;
pub use crate::registry::ErrorCodeInfo;
pub use crate::collector::ErrorCollector;
pub use crate::collector::CollectError;
pub use crate::logging::ErrorLogger;
pub use crate::logging::register_logger;
pub use crate::logging::log_error;
pub use crate::logging::logger;
pub use crate::async_error::AsyncForgeError;
pub use crate::async_error::AsyncResult;
pub use crate::macros::*;

Modules§

async_error
async_error_impl
collector
console_theme
Console theming for error display in CLI applications
context
error
group_macro
logging
macros
recovery
Error recovery patterns for handling transient errors
registry

Macros§

define_errors
group
Macro for composing multi-error enums with automatic From<OtherError> conversions.

Derive Macros§

ModError
Derive macro for ModError