Skip to main content

uni_query/query/df_graph/
locy_errors.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4//! Error types for the Locy native execution engine.
5
6use std::fmt;
7
8/// Runtime errors specific to Locy evaluation.
9#[derive(Debug)]
10pub enum LocyRuntimeError {
11    /// Fixpoint iteration did not converge within the allowed limit.
12    NonConvergence { iterations: usize },
13    /// A monotonic aggregate detected a decrease in value.
14    MonotonicViolation { rule: String, column: String },
15    /// Stratification detected a cycle through negation.
16    NegationCycle { rules: Vec<String> },
17    /// A derived relation exceeded its memory budget.
18    MemoryLimitExceeded {
19        rule: String,
20        bytes: usize,
21        limit: usize,
22    },
23}
24
25impl fmt::Display for LocyRuntimeError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Self::NonConvergence { iterations } => {
29                write!(
30                    f,
31                    "fixpoint did not converge: max iterations ({iterations}) exceeded"
32                )
33            }
34            Self::MonotonicViolation { rule, column } => {
35                write!(f, "monotonic violation in rule '{rule}', column '{column}'")
36            }
37            Self::NegationCycle { rules } => {
38                write!(
39                    f,
40                    "negation cycle detected among rules: {}",
41                    rules.join(", ")
42                )
43            }
44            Self::MemoryLimitExceeded { rule, bytes, limit } => {
45                write!(
46                    f,
47                    "rule '{rule}' exceeded memory limit ({bytes} bytes > {limit} byte limit)"
48                )
49            }
50        }
51    }
52}
53
54impl std::error::Error for LocyRuntimeError {}