use std::sync::{Arc, Weak}; use crate::types::{Metadata, NodeValue, Relation, RelationResolution, ValueNode}; #[derive(Debug, Clone, serde::Serialize)] #[serde(tag = "type", content = "predecessor", rename_all = "snake_case")] pub enum ValueTracePredecessor { Mandatory(Box>>), OneOf(Vec>>), } #[derive(Debug, Clone, serde::Serialize)] #[serde(tag = "type", content = "trace", rename_all = "snake_case")] pub enum AnalysisTrace { Value { value: NodeValue, relation: Relation, predecessors: Option>, info: Option<&'static str>, metadata: Option>, }, AllAggregation { unsatisfied: Vec>>, info: Option<&'static str>, metadata: Option>, }, AnyAggregation { unsatisfied: Vec>>, info: Option<&'static str>, metadata: Option>, }, InAggregation { expected: Vec, found: Option, relation: Relation, info: Option<&'static str>, metadata: Option>, }, Contradiction { relation: RelationResolution, }, } #[derive(Debug, Clone, serde::Serialize, thiserror::Error)] #[serde(tag = "type", content = "info", rename_all = "snake_case")] pub enum GraphError { #[error("An edge was not found in the graph")] EdgeNotFound, #[error("Attempted to create a conflicting edge between two nodes")] ConflictingEdgeCreated, #[error("Cycle detected in graph")] CycleDetected, #[error("Domain wasn't found in the Graph")] DomainNotFound, #[error("Malformed Graph: {reason}")] MalformedGraph { reason: String }, #[error("A node was not found in the graph")] NodeNotFound, #[error("A value node was not found: {0:#?}")] ValueNodeNotFound(V), #[error("No values provided for an 'in' aggregator node")] NoInAggregatorValues, #[error("Error during analysis: {0:#?}")] AnalysisError(Weak>), } impl GraphError { pub fn get_analysis_trace(self) -> Result>, Self> { match self { Self::AnalysisError(trace) => Ok(trace), _ => Err(self), } } }