Skip to main content

Crate error_forge

Crate error_forge 

Source
Expand description

§Error Forge

Error Forge is a pragmatic Rust error-handling crate for applications that need structured metadata, readable output, and operational hooks without forcing a single application architecture.

It provides:

  • ForgeError for stable error metadata
  • AppError for immediate use in small and medium projects
  • define_errors! for declarative custom enums
  • group! for coarse-grained composition
  • optional derive support with #[derive(ModError)]
  • context wrapping, error codes, collectors, logging hooks, and console formatting
  • synchronous retry and circuit-breaker helpers in recovery

§Quick Start

use error_forge::{define_errors, ForgeError};

define_errors! {
    pub enum ServiceError {
        #[error(display = "Configuration error: {message}", message)]
        #[kind(Config, status = 500)]
        Config { message: String },

        #[error(display = "Request to {endpoint} failed", endpoint)]
        #[kind(Network, retryable = true, status = 503)]
        Network { endpoint: String },
    }
}

let error = ServiceError::config("Missing DATABASE_URL".to_string());
assert_eq!(error.kind(), "Config");

§Built-in Formatting

use error_forge::{console_theme::print_error, AppError};

let error = AppError::config("Database connection failed");
print_error(&error);

Re-exports§

pub use crate::console_theme::install_panic_hook;
pub use crate::console_theme::print_error;
pub use crate::console_theme::ConsoleTheme;
pub use crate::error::AppError;
pub use crate::error::ForgeError;
pub use crate::error::Result;
pub use crate::context::ContextError;
pub use crate::context::ResultExt;
pub use crate::registry::register_error_code;
pub use crate::registry::CodedError;
pub use crate::registry::ErrorCodeInfo;
pub use crate::registry::ErrorRegistry;
pub use crate::registry::WithErrorCode;
pub use crate::collector::CollectError;
pub use crate::collector::ErrorCollector;
pub use crate::logging::log_error;
pub use crate::logging::logger;
pub use crate::logging::register_logger;
pub use crate::logging::ErrorLogger;
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