use std::fmt;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum InstError {
#[error("node not found: {0}")]
NodeNotFound(u32),
#[error("vertex not found in schema: {0}")]
VertexNotFound(String),
#[error("root node missing from instance")]
MissingRoot,
#[error("dangling arc: ({src}, {tgt})")]
DanglingArc {
src: u32,
tgt: u32,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RestrictError {
#[error("no edge found between {src} and {tgt} in target schema")]
NoEdgeFound {
src: String,
tgt: String,
},
#[error("ambiguous edge between {src} and {tgt}: {count} candidates")]
AmbiguousEdge {
src: String,
tgt: String,
count: usize,
},
#[error("root node was pruned during restriction")]
RootPruned,
#[error("fan reconstruction failed for hyper-edge {hyper_edge_id}: {detail}")]
FanReconstructionFailed {
hyper_edge_id: String,
detail: String,
},
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ParseError {
#[error("root vertex not found in schema: {0}")]
RootVertexNotFound(String),
#[error("expected JSON object at path {path}")]
ExpectedObject {
path: String,
},
#[error("expected JSON array at path {path}")]
ExpectedArray {
path: String,
},
#[error("unknown edge target at path {path}: {detail}")]
UnknownEdgeTarget {
path: String,
detail: String,
},
#[error("invalid value at path {path}: {detail}")]
InvalidValue {
path: String,
detail: String,
},
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ValidationError {
InvalidAnchor {
node_id: u32,
anchor: String,
},
InvalidEdge {
parent: u32,
child: u32,
detail: String,
},
MissingRoot,
UnreachableNode {
node_id: u32,
},
MissingRequiredEdge {
node_id: u32,
edge: String,
},
ParentMapInconsistent {
node_id: u32,
detail: String,
},
InvalidFan {
hyper_edge_id: String,
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}"),
}
}
}