use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CpdagError {
FileNotFound(String),
Io(String),
MissingHeader,
Parse(String),
VertexOutOfRange {
index: usize,
num_vertices: usize,
},
Graph(String),
}
impl fmt::Display for CpdagError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CpdagError::FileNotFound(p) => write!(f, "CPDAG file not found: {}", p),
CpdagError::Io(e) => write!(f, "CPDAG file IO error: {}", e),
CpdagError::MissingHeader => {
write!(f, "CPDAG file is missing the '# … vertices=N' header line")
}
CpdagError::Parse(e) => write!(f, "CPDAG file parse error: {}", e),
CpdagError::VertexOutOfRange {
index,
num_vertices,
} => write!(
f,
"CPDAG vertex index {} is out of range for {} vertices",
index, num_vertices
),
CpdagError::Graph(e) => write!(f, "CPDAG graph construction failed: {}", e),
}
}
}
impl std::error::Error for CpdagError {}