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:
ForgeErrorfor stable error metadataAppErrorfor immediate use in small and medium projectsdefine_errors!for declarative custom enumsgroup!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