use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraphError {
UnknownNode { edge: String, id: String },
DuplicateEdge { edge: String },
IntoInput { edge: String },
FromOutput { edge: String },
Cycle { path: Vec<String> },
Disconnected { node: String },
}
impl fmt::Display for GraphError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownNode { edge, id } => write!(
f,
"edge \"{edge}\" connects to \"{id}\", which is not a node at this level"
),
Self::DuplicateEdge { edge } => write!(
f,
"edge \"{edge}\" repeats an earlier edge between the same two nodes"
),
Self::IntoInput { edge } => write!(f, "edge \"{edge}\" leads into an input node"),
Self::FromOutput { edge } => write!(f, "edge \"{edge}\" leads out of an output node"),
Self::Cycle { path } => write!(f, "edges form a cycle: {}", path.join(" → ")),
Self::Disconnected { node } => {
write!(f, "node \"{node}\" is not connected to any edge")
}
}
}
}
impl std::error::Error for GraphError {}