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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//! Error handling for Ferrous Forge
//!
//! This module provides a unified error handling system for all Ferrous Forge operations.
/// Ferrous Forge specific errors
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// IO errors (file operations, etc.)
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
/// Configuration errors
#[error("Configuration error: {0}")]
Config(String),
/// Validation errors
#[error("Validation error: {0}")]
Validation(String),
/// Template errors
#[error("Template error: {0}")]
Template(String),
/// Update system errors
#[error("Update error: {0}")]
Update(String),
/// Standards enforcement errors
#[error("Standards violation: {0}")]
Standards(String),
/// CLI argument errors
#[error("CLI error: {0}")]
Cli(String),
/// External process errors
#[error("Process error: {0}")]
Process(String),
/// Serialization errors
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
/// TOML parsing errors
#[error("TOML error: {0}")]
Toml(#[from] toml::de::Error),
/// Network/HTTP errors
#[error("Network error: {0}")]
Network(String),
/// Semver parsing errors
#[error("Version error: {0}")]
Version(#[from] semver::Error),
/// Parse errors
#[error("Parse error: {0}")]
Parse(String),
/// Rust not found
#[error("Rust not found: {0}")]
RustNotFound(String),
/// Command execution error
#[error("Command error: {0}")]
Command(String),
/// File not found
#[error("File not found: {0}")]
FileNotFound(String),
/// Rate limited
#[error("Rate limited: retry after {0} seconds")]
RateLimited(u64),
/// Migration error
#[error("Migration error: {0}")]
Migration(String),
/// Regex error
#[error("Regex error: {0}")]
Regex(#[from] regex::Error),
/// UTF-8 conversion error
#[error("UTF-8 error: {0}")]
Utf8(#[from] std::str::Utf8Error),
/// Safety pipeline error
#[error("Safety error: {0}")]
Safety(String),
/// Safety pipeline blocked operation
#[error("Safety blocked: {0}")]
SafetyBlocked(String),
}
/// Result type alias for Ferrous Forge operations
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
/// Create a new configuration error
///
/// # Examples
///
/// ```rust
/// # use ferrous_forge::Error;
/// let err = Error::config("missing config key");
/// assert!(err.to_string().contains("missing config key"));
/// ```
pub fn config(msg: impl Into<String>) -> Self {
Self::Config(msg.into())
}
/// Create a new validation error
///
/// # Examples
///
/// ```rust
/// # use ferrous_forge::Error;
/// let err = Error::validation("invalid field value");
/// assert!(err.to_string().contains("invalid field value"));
/// ```
pub fn validation(msg: impl Into<String>) -> Self {
Self::Validation(msg.into())
}
/// Create a new template error
pub fn template(msg: impl Into<String>) -> Self {
Self::Template(msg.into())
}
/// Create a new update error
pub fn update(msg: impl Into<String>) -> Self {
Self::Update(msg.into())
}
/// Create a new standards error
pub fn standards(msg: impl Into<String>) -> Self {
Self::Standards(msg.into())
}
/// Create a new CLI error
pub fn cli(msg: impl Into<String>) -> Self {
Self::Cli(msg.into())
}
/// Create a new process error
///
/// # Examples
///
/// ```rust
/// # use ferrous_forge::Error;
/// let err = Error::process("cargo build failed");
/// assert!(err.to_string().contains("cargo build failed"));
/// ```
pub fn process(msg: impl Into<String>) -> Self {
Self::Process(msg.into())
}
/// Create a new parse error
pub fn parse(msg: impl Into<String>) -> Self {
Self::Parse(msg.into())
}
/// Create a new rust not found error
pub fn rust_not_found(msg: impl Into<String>) -> Self {
Self::RustNotFound(msg.into())
}
/// Create a new command error
pub fn command(msg: impl Into<String>) -> Self {
Self::Command(msg.into())
}
/// Create a new file not found error
pub fn file_not_found(msg: impl Into<String>) -> Self {
Self::FileNotFound(msg.into())
}
/// Create a new rate limited error
pub fn rate_limited(retry_after: u64) -> Self {
Self::RateLimited(retry_after)
}
/// Create a new IO error from a string
pub fn io(msg: impl Into<String>) -> Self {
Self::Io(std::io::Error::other(msg.into()))
}
/// Create a new security error
pub fn security(msg: impl Into<String>) -> Self {
Self::Validation(format!("Security: {}", msg.into()))
}
/// Create a new migration error
pub fn migration(msg: impl Into<String>) -> Self {
Self::Migration(msg.into())
}
/// Create a new network error
pub fn network(msg: impl Into<String>) -> Self {
Self::Network(msg.into())
}
/// Create a new safety error
pub fn safety(msg: impl Into<String>) -> Self {
Self::Safety(msg.into())
}
/// Create a new safety blocked error
pub fn safety_blocked(msg: impl Into<String>) -> Self {
Self::SafetyBlocked(msg.into())
}
/// Create a new tool not found error
pub fn tool_not_found(tool: impl Into<String>) -> Self {
Self::Process(format!("Tool not found: {}", tool.into()))
}
}
/// Convert anyhow errors to our error type
impl From<anyhow::Error> for Error {
fn from(err: anyhow::Error) -> Self {
Self::Process(err.to_string())
}
}
/// Convert reqwest errors to our error type
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Self::Network(err.to_string())
}
}