use std::fmt;
pub type Result<T> = std::result::Result<T, PldagError>;
#[derive(Debug, Clone, PartialEq)]
pub enum PldagError {
CycleDetected {
node_id: String,
},
NodeNotFound {
node_id: String,
},
NodeOutOfBounds {
node_id: String,
got_bound: (i32, i32),
expected_bound: (i32, i32),
},
MaxIterationsExceeded {
max_iters: usize,
},
NodeReferenced {
node_id: String,
referencing_nodes: Vec<String>,
},
}
impl fmt::Display for PldagError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PldagError::CycleDetected { node_id } => {
write!(f, "Cycle detected in DAG at node '{}'", node_id)
}
PldagError::NodeNotFound { node_id } => {
write!(f, "Node '{}' not found in storage", node_id)
}
PldagError::NodeOutOfBounds {
node_id,
got_bound,
expected_bound,
} => {
write!(
f,
"Node '{}' out of bounds: got {:?}, expected {:?}",
node_id, got_bound, expected_bound
)
}
PldagError::MaxIterationsExceeded { max_iters } => {
write!(f, "Max iterations exceeded during tightening: {}", max_iters)
}
PldagError::NodeReferenced {
node_id,
referencing_nodes,
} => {
write!(
f,
"Cannot delete node '{}'; it is referenced by nodes: {:?}",
node_id, referencing_nodes
)
}
}
}
}
impl std::error::Error for PldagError {}