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
//! Error types returned by public bot-forge operations.
use std::error::Error;
use std::fmt::{self, Display};
use std::io;
use std::path::PathBuf;
#[derive(Debug)]
/// Failure categories exposed by configuration, planning, execution, and persistence APIs.
pub enum ForgeError {
/// An I/O operation failed at the associated path.
Io {
/// Filesystem path associated with the failed operation.
path: PathBuf,
/// Underlying operating-system I/O error.
source: io::Error,
},
/// Structured input or persisted state could not be parsed.
Parse(String),
/// Configuration or a validated state invariant was rejected.
Config(String),
/// An external command or managed process failed.
Command(String),
/// A network transfer or integrity verification failed.
Network(String),
}
impl Display for ForgeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ForgeError::Io { path, source } => write!(f, "{}: {}", path.display(), source),
ForgeError::Parse(message) => write!(f, "parse error: {message}"),
ForgeError::Config(message) => write!(f, "configuration error: {message}"),
ForgeError::Command(message) => write!(f, "command error: {message}"),
ForgeError::Network(message) => write!(f, "network or verification error: {message}"),
}
}
}
impl Error for ForgeError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
ForgeError::Io { source, .. } => Some(source),
_ => None,
}
}
}