error_forge/
lib.rs

1//! # Error Forge
2//! 
3//! A high-performance, flexible Rust error framework for defining, formatting, chaining, 
4//! and managing rich custom errors across large-scale applications.
5//!
6//! ## Overview
7//!
8//! Error Forge provides a comprehensive solution for error handling in Rust applications,
9//! focusing on performance, flexibility, and developer ergonomics. It enables defining 
10//! structured error types with minimal boilerplate, making error handling more efficient
11//! and maintainable.
12//!
13//! ## Key Features
14//!
15//! - **`define_errors!` macro** - Create rich error enums with minimal boilerplate
16//! - **`#[derive(ModError)]` proc-macro** - "Lazy mode" errors with attribute-based configuration
17//! - **`group!` macro** - Compose multi-error enums with automatic `From` conversions
18//! - **Console theming** - ANSI-colored errors for CLI applications
19//! - **Built-in panic hook** - Enhanced panic formatting
20//! - **ForgeError trait** - Unified interface for error handling
21//! - **Serialization support** - Optional serde integration
22//!
23//! ## Quick Start
24//!
25//! ```ignore
26//! use error_forge::{define_errors, ForgeError};
27//! 
28//! // Define our error type
29//! define_errors! {
30//!     #[derive(Debug)]
31//!     pub enum AppError {
32//!         #[error(display = "Configuration error: {message}")]
33//!         #[kind(Config, retryable = false, status = 500)]
34//!         Config { message: String },
35//!         
36//!         #[error(display = "Database error: {message}")]
37//!         #[kind(Database, retryable = true, status = 503)]
38//!         Database { message: String },
39//!     }
40//! }
41//!
42//! // Use the error type
43//! fn main() -> Result<(), error_forge::AppError> {
44//!     if cfg!(debug_assertions) {
45//!         return Err(error_forge::AppError::config("Missing configuration"));
46//!     }
47//!     Ok(())
48//! }
49//! ```
50//!
51//! ## Enhanced Error Reporting
52//!
53//! ```rust
54//! // Import the predefined AppError type from the library
55//! use error_forge::{console_theme::print_error, AppError};
56//!
57//! let error = AppError::config("Database connection failed");
58//! print_error(&error);  // Displays a nicely formatted error message
59//! ```
60pub mod error;
61pub mod macros;
62pub mod group_macro;
63pub mod console_theme;
64pub mod context;
65pub mod registry;
66pub mod collector;
67pub mod logging;
68
69// Re-export core types and traits
70pub use crate::error::{ForgeError, Result, AppError};
71pub use crate::console_theme::{ConsoleTheme, print_error, install_panic_hook};
72
73// Re-export context module
74pub use crate::context::{ContextError, ResultExt};
75
76// Re-export registry module
77pub use crate::registry::{WithErrorCode, CodedError, register_error_code, ErrorRegistry, ErrorCodeInfo};
78
79// Re-export collector module
80pub use crate::collector::{ErrorCollector, CollectError};
81
82// Re-export logging module
83pub use crate::logging::{ErrorLogger, register_logger, log_error, logger};
84
85#[cfg(feature = "serde")]
86extern crate serde;
87
88// Re-export macros for convenient use
89#[allow(unused_imports)]
90pub use crate::macros::*;
91
92// Optional re-export of the proc macro
93#[cfg(feature = "derive")]
94pub use error_forge_derive::*;
95
96// Extension methods are implemented in error.rs
97
98// Extension methods are implemented in error.rs
99
100#[cfg(test)]
101mod tests {
102    use crate::ForgeError;
103	#[test]
104	fn it_works() {
105		assert_eq!(2 + 2, 4);
106	}
107
108	#[test]
109	fn test_error_display() {
110		let err = crate::error::AppError::config("Test error");
111		assert!(err.to_string().contains("Test error"));
112	}
113
114	#[test]
115	fn test_error_kind() {
116		let err = crate::error::AppError::config("Test error");
117		assert_eq!(err.kind(), "Config");
118	}
119}