antecedent_graph/
error.rs1use core::fmt;
6
7use antecedent_core::{Lag, VariableId};
8
9#[derive(Clone, Debug, Eq, PartialEq)]
11pub enum GraphError {
12 UnknownNode {
14 id: u32,
16 },
17 UnknownVariableName {
19 name: String,
21 },
22 Cycle {
24 from: u32,
26 to: u32,
28 },
29 InvalidEndpoints {
31 message: &'static str,
33 },
34 ContemporaneousSelfEdge {
36 variable: VariableId,
38 },
39 DuplicateEdge {
41 from: u32,
43 to: u32,
45 },
46 InvalidLag {
48 lag: Lag,
50 },
51 TooManyNodes,
53 SearchBudgetExhausted {
59 max_paths: usize,
61 max_len: usize,
63 },
64}
65
66impl fmt::Display for GraphError {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 match self {
69 Self::UnknownNode { id } => write!(f, "unknown dense node {id}"),
70 Self::UnknownVariableName { name } => write!(f, "unknown variable name '{name}'"),
71 Self::Cycle { from, to } => write!(f, "edge {from}->{to} would create a cycle"),
72 Self::InvalidEndpoints { message } => write!(f, "invalid endpoints: {message}"),
73 Self::ContemporaneousSelfEdge { variable } => {
74 write!(f, "contemporaneous self-edge on {variable}")
75 }
76 Self::DuplicateEdge { from, to } => write!(f, "duplicate edge {from}->{to}"),
77 Self::InvalidLag { lag } => write!(f, "invalid lag {lag}"),
78 Self::TooManyNodes => write!(f, "too many nodes"),
79 Self::SearchBudgetExhausted { max_paths, max_len } => {
80 write!(f, "path search budget exhausted (max_paths={max_paths}, max_len={max_len})")
81 }
82 }
83 }
84}
85
86impl std::error::Error for GraphError {}