Skip to main content

bot_forge/
error.rs

1//! Error types returned by public bot-forge operations.
2
3use std::error::Error;
4use std::fmt::{self, Display};
5use std::io;
6use std::path::PathBuf;
7
8#[derive(Debug)]
9/// Failure categories exposed by configuration, planning, execution, and persistence APIs.
10pub enum ForgeError {
11    /// An I/O operation failed at the associated path.
12    Io {
13        /// Filesystem path associated with the failed operation.
14        path: PathBuf,
15        /// Underlying operating-system I/O error.
16        source: io::Error,
17    },
18    /// Structured input or persisted state could not be parsed.
19    Parse(String),
20    /// Configuration or a validated state invariant was rejected.
21    Config(String),
22    /// An external command or managed process failed.
23    Command(String),
24    /// A network transfer or integrity verification failed.
25    Network(String),
26}
27
28impl Display for ForgeError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            ForgeError::Io { path, source } => write!(f, "{}: {}", path.display(), source),
32            ForgeError::Parse(message) => write!(f, "parse error: {message}"),
33            ForgeError::Config(message) => write!(f, "configuration error: {message}"),
34            ForgeError::Command(message) => write!(f, "command error: {message}"),
35            ForgeError::Network(message) => write!(f, "network or verification error: {message}"),
36        }
37    }
38}
39
40impl Error for ForgeError {
41    fn source(&self) -> Option<&(dyn Error + 'static)> {
42        match self {
43            ForgeError::Io { source, .. } => Some(source),
44            _ => None,
45        }
46    }
47}