1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! # 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`]
//!
//! ## Messages for users and for logs
//!
//! [`ForgeError::user_message`] is safe to show end users: by default it
//! is the error's caption and never carries the error's data. `Display`,
//! `Debug` and [`ForgeError::dev_message`] carry everything the error
//! holds (paths, endpoints, source errors, field values), so keep them
//! for logs, and wrap secrets in [`Redacted`] so they print as
//! `[redacted]` even there.
//!
//! ## 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-export core types and traits
pub use crate;
pub use crate;
pub use crateRedacted;
// Historical re-export. `Result` shadows `std::result::Result` in
// glob imports; deprecated in favour of `AppResult`. Kept for
// source compatibility through the `1.x` line.
pub use crateResult;
// Re-export context module
pub use crate;
// Re-export registry module
pub use crate;
// Re-export collector module
pub use crate;
// Re-export logging module
pub use crate;
// Re-export async module (when enabled)
pub use crate;
// Re-export hook types from `macros` — explicitly named so the
// public surface stays under our control. `define_errors!` and
// `group!` are re-exported automatically because they are
// `#[macro_export]`'d.
pub use crate;
// Optional re-export of the proc macro
pub use ModError;
/// Internal re-exports for use by macros expanded in user crates.
///
/// This module is not part of the public API. Items here may
/// change at any time without notice. They are exposed only so
/// that `define_errors!` (and other macros that expand into user
/// code) can reference dependencies through `$crate::__private::*`
/// without forcing every user to add those crates to their own
/// `Cargo.toml`.
// Extension methods are implemented in error.rs
/// Runs every `rust` code block in `docs/API.md` as a doctest so the
/// narrative reference cannot drift from the API. Several examples use
/// `#[derive(ModError)]` and `AsyncForgeError`, so this only builds when
/// both features are on (CI runs `cargo test --all-features`).
;
/// Runs every `rust` code block in `README.md` as a doctest. The derive
/// example needs the `derive` feature. Doctests are compiled with this
/// crate's features as `cfg`s, so with `serde` on, the `serde` derive
/// that `define_errors!` adds would also apply to the README enums,
/// whose `source` fields are not serializable; the README is checked by
/// the feature combinations without `serde` instead.
;