Skip to main content

datalog_structural_model/ir/error/
code.rs

1//! Stable kebab-case codes of [`ProgramValidationError`] variants.
2
3use super::variants::ProgramValidationError;
4use crate::error_code::ErrorCode;
5
6impl ProgramValidationError {
7    /// Code of [`Self::UnsafeRule`].
8    pub const CODE_UNSAFE_RULE: ErrorCode = ErrorCode::new("unsafe-rule");
9    /// Code of [`Self::UnusedExistentialVariable`].
10    pub const CODE_UNUSED_EXISTENTIAL_VARIABLE: ErrorCode =
11        ErrorCode::new("unused-existential-variable");
12    /// Code of [`Self::ExistentialVariableBoundInBody`].
13    pub const CODE_EXISTENTIAL_VARIABLE_BOUND_IN_BODY: ErrorCode =
14        ErrorCode::new("existential-variable-bound-in-body");
15    /// Code of [`Self::UnsafeNegation`].
16    pub const CODE_UNSAFE_NEGATION: ErrorCode = ErrorCode::new("unsafe-negation");
17    /// Code of [`Self::UnsafeFilter`].
18    pub const CODE_UNSAFE_FILTER: ErrorCode = ErrorCode::new("unsafe-filter");
19    /// Code of [`Self::UnsafeBind`].
20    pub const CODE_UNSAFE_BIND: ErrorCode = ErrorCode::new("unsafe-bind");
21    /// Code of [`Self::UnsafeAggregate`].
22    pub const CODE_UNSAFE_AGGREGATE: ErrorCode = ErrorCode::new("unsafe-aggregate");
23    /// Code of [`Self::NestedAggregateInInnerBody`].
24    pub const CODE_NESTED_AGGREGATE: ErrorCode = ErrorCode::new("nested-aggregate");
25    /// Code of [`Self::UnstratifiableCycle`].
26    pub const CODE_UNSTRATIFIABLE_CYCLE: ErrorCode = ErrorCode::new("unstratifiable-cycle");
27    /// Code of [`Self::NegationUnderEqualityMode`].
28    pub const CODE_NEGATION_UNDER_EQUALITY_MODE: ErrorCode =
29        ErrorCode::new("negation-under-equality-mode");
30    /// Code of [`Self::AggregationUnderEqualityMode`].
31    pub const CODE_AGGREGATION_UNDER_EQUALITY_MODE: ErrorCode =
32        ErrorCode::new("aggregation-under-equality-mode");
33    /// Code of [`Self::SkolemInBodyAtom`].
34    pub const CODE_SKOLEM_IN_BODY: ErrorCode = ErrorCode::new("skolem-in-body");
35    /// Code of [`Self::TripleTermNestingExceeded`].
36    pub const CODE_TRIPLE_TERM_NESTING_EXCEEDED: ErrorCode =
37        ErrorCode::new("triple-term-nesting-exceeded");
38    /// Code of [`Self::InvalidSkolemArguments`].
39    pub const CODE_INVALID_SKOLEM_ARGUMENTS: ErrorCode = ErrorCode::new("invalid-skolem-arguments");
40
41    /// Code of [`Self::RuleCountExceeded`].
42    pub const CODE_RULE_COUNT_EXCEEDED: ErrorCode = ErrorCode::new("rule-count-exceeded");
43    /// Code of [`Self::BodyLengthExceeded`].
44    pub const CODE_BODY_LENGTH_EXCEEDED: ErrorCode = ErrorCode::new("body-length-exceeded");
45    /// Code of [`Self::SkolemDepthExceeded`].
46    pub const CODE_SKOLEM_DEPTH_EXCEEDED: ErrorCode = ErrorCode::new("skolem-depth-exceeded");
47
48    /// Stable kebab-case code of this variant.
49    #[must_use]
50    pub fn code(&self) -> ErrorCode {
51        match self {
52            Self::UnsafeRule { .. } => Self::CODE_UNSAFE_RULE,
53            Self::UnusedExistentialVariable { .. } => Self::CODE_UNUSED_EXISTENTIAL_VARIABLE,
54            Self::ExistentialVariableBoundInBody { .. } => {
55                Self::CODE_EXISTENTIAL_VARIABLE_BOUND_IN_BODY
56            }
57            Self::UnsafeNegation { .. } => Self::CODE_UNSAFE_NEGATION,
58            Self::UnsafeFilter { .. } => Self::CODE_UNSAFE_FILTER,
59            Self::UnsafeBind { .. } => Self::CODE_UNSAFE_BIND,
60            Self::UnsafeAggregate { .. } => Self::CODE_UNSAFE_AGGREGATE,
61            Self::NestedAggregateInInnerBody { .. } => Self::CODE_NESTED_AGGREGATE,
62            Self::UnstratifiableCycle(_) => Self::CODE_UNSTRATIFIABLE_CYCLE,
63            Self::NegationUnderEqualityMode { .. } => Self::CODE_NEGATION_UNDER_EQUALITY_MODE,
64            Self::AggregationUnderEqualityMode { .. } => Self::CODE_AGGREGATION_UNDER_EQUALITY_MODE,
65            Self::SkolemInBodyAtom { .. } => Self::CODE_SKOLEM_IN_BODY,
66            Self::TripleTermNestingExceeded { .. } => Self::CODE_TRIPLE_TERM_NESTING_EXCEEDED,
67            Self::InvalidSkolemArguments { .. } => Self::CODE_INVALID_SKOLEM_ARGUMENTS,
68            Self::RuleCountExceeded { .. } => Self::CODE_RULE_COUNT_EXCEEDED,
69            Self::BodyLengthExceeded { .. } => Self::CODE_BODY_LENGTH_EXCEEDED,
70            Self::SkolemDepthExceeded { .. } => Self::CODE_SKOLEM_DEPTH_EXCEEDED,
71        }
72    }
73}