1use std::error::Error;
4use std::fmt::{self, Display};
5use std::io;
6use std::path::PathBuf;
7
8#[derive(Debug)]
9pub enum ForgeError {
11 Io {
13 path: PathBuf,
15 source: io::Error,
17 },
18 Parse(String),
20 Config(String),
22 Command(String),
24 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}