1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//! Error types for instance operations.
use std::fmt;
/// Errors from instance construction or manipulation.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum InstError {
/// A node ID was referenced but not found.
#[error("node not found: {0}")]
NodeNotFound(u32),
/// A vertex ID was referenced but not found in the schema.
#[error("vertex not found in schema: {0}")]
VertexNotFound(String),
/// The root node is missing.
#[error("root node missing from instance")]
MissingRoot,
/// An arc references a nonexistent node.
#[error("dangling arc: ({src}, {tgt})")]
DanglingArc {
/// Source node ID.
src: u32,
/// Target node ID.
tgt: u32,
},
}
/// Errors from the restrict operation.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RestrictError {
/// No edge found between two vertices after ancestor contraction.
#[error("no edge found between {src} and {tgt} in target schema")]
NoEdgeFound {
/// Source vertex anchor.
src: String,
/// Target vertex anchor.
tgt: String,
},
/// Multiple edges found without a resolver entry.
#[error("ambiguous edge between {src} and {tgt}: {count} candidates")]
AmbiguousEdge {
/// Source vertex anchor.
src: String,
/// Target vertex anchor.
tgt: String,
/// Number of candidate edges.
count: usize,
},
/// The root was pruned during restriction.
#[error("root node was pruned during restriction")]
RootPruned,
/// Fan reconstruction failed.
#[error("fan reconstruction failed for hyper-edge {hyper_edge_id}: {detail}")]
FanReconstructionFailed {
/// The hyper-edge ID.
hyper_edge_id: String,
/// Details about the failure.
detail: String,
},
/// Cartesian product exceeded the configured size limit.
#[error("product size {actual} exceeds limit {limit} for vertex {vertex}")]
ProductSizeExceeded {
/// The target vertex whose fiber product is too large.
vertex: String,
/// The actual product size.
actual: usize,
/// The configured limit.
limit: usize,
},
/// Multi-element fiber encountered where only single-element fibers
/// are supported (e.g., W-type right Kan extension).
#[error("multi-element fiber for vertex {vertex}: {count} source vertices")]
MultiElementFiber {
/// The target vertex with multiple preimages.
vertex: String,
/// Number of source vertices in the fiber.
count: usize,
},
}
/// Errors from JSON parsing.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ParseError {
/// The root vertex was not found in the schema.
#[error("root vertex not found in schema: {0}")]
RootVertexNotFound(String),
/// Expected a JSON object.
#[error("expected JSON object at path {path}")]
ExpectedObject {
/// JSON path where the error occurred.
path: String,
},
/// Expected a JSON array.
#[error("expected JSON array at path {path}")]
ExpectedArray {
/// JSON path where the error occurred.
path: String,
},
/// An edge references an unknown vertex kind.
#[error("unknown edge target at path {path}: {detail}")]
UnknownEdgeTarget {
/// JSON path where the error occurred.
path: String,
/// Details.
detail: String,
},
/// A value could not be parsed.
#[error("invalid value at path {path}: {detail}")]
InvalidValue {
/// JSON path where the error occurred.
path: String,
/// Details.
detail: String,
},
/// JSON structure error.
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
}
/// A validation error found when checking a W-type instance against a schema.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValidationError {
/// A node's anchor vertex is not in the schema.
InvalidAnchor {
/// The offending node ID.
node_id: u32,
/// The anchor that was not found.
anchor: String,
},
/// An arc's edge is not in the schema.
InvalidEdge {
/// Parent node ID.
parent: u32,
/// Child node ID.
child: u32,
/// Details.
detail: String,
},
/// The root node is not present in the node set.
MissingRoot,
/// A child node is unreachable from the root.
UnreachableNode {
/// The unreachable node ID.
node_id: u32,
},
/// A required edge is missing from a node.
MissingRequiredEdge {
/// The node ID.
node_id: u32,
/// Description of the missing edge.
edge: String,
},
/// Parent map inconsistency.
ParentMapInconsistent {
/// The node with the inconsistency.
node_id: u32,
/// Details.
detail: String,
},
/// Fan references a nonexistent node.
InvalidFan {
/// The hyper-edge ID.
hyper_edge_id: String,
/// Details.
detail: String,
},
}
impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidAnchor { node_id, anchor } => {
write!(f, "node {node_id} has invalid anchor: {anchor}")
}
Self::InvalidEdge {
parent,
child,
detail,
} => write!(f, "invalid edge ({parent}, {child}): {detail}"),
Self::MissingRoot => write!(f, "root node is missing"),
Self::UnreachableNode { node_id } => {
write!(f, "node {node_id} is unreachable from root")
}
Self::MissingRequiredEdge { node_id, edge } => {
write!(f, "node {node_id} missing required edge: {edge}")
}
Self::ParentMapInconsistent { node_id, detail } => {
write!(f, "parent map inconsistency at node {node_id}: {detail}")
}
Self::InvalidFan {
hyper_edge_id,
detail,
} => write!(f, "invalid fan for hyper-edge {hyper_edge_id}: {detail}"),
}
}
}