tensorlogic_infer/causal/error.rs
1//! Error type for causal inference computations.
2//!
3//! Defines [`CausalError`] and its `Display` / `Error` trait implementations.
4
5// ---------------------------------------------------------------------------
6// Error type
7// ---------------------------------------------------------------------------
8
9/// Errors that can occur during causal inference computations.
10#[derive(Debug)]
11pub enum CausalError {
12 /// A named node was not found in the graph.
13 NodeNotFound(String),
14 /// A cycle was detected, violating the DAG requirement.
15 CycleDetected,
16 /// Sample dimension does not match the number of variables.
17 DimensionMismatch,
18 /// Not enough data for the requested computation.
19 InsufficientData,
20 /// No directed causal path exists between the specified nodes.
21 NoCausalPath,
22 /// A numerical computation failed (e.g. division by zero).
23 NumericalError(String),
24}
25
26impl std::fmt::Display for CausalError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 CausalError::NodeNotFound(name) => {
30 write!(f, "causal: node '{}' not found in graph", name)
31 }
32 CausalError::CycleDetected => {
33 write!(f, "causal: cycle detected — graph is not a DAG")
34 }
35 CausalError::DimensionMismatch => {
36 write!(
37 f,
38 "causal: sample dimension does not match number of variables"
39 )
40 }
41 CausalError::InsufficientData => {
42 write!(f, "causal: insufficient data for the requested computation")
43 }
44 CausalError::NoCausalPath => {
45 write!(
46 f,
47 "causal: no directed causal path between the specified nodes"
48 )
49 }
50 CausalError::NumericalError(msg) => {
51 write!(f, "causal: numerical error — {}", msg)
52 }
53 }
54 }
55}
56
57impl std::error::Error for CausalError {}