rbe/
rbe_error.rs

1use crate::failures::Failures;
2use crate::rbe1::Rbe;
3use crate::Cardinality;
4use crate::Key;
5use crate::Keys;
6use crate::Ref;
7use crate::Value;
8use crate::Values;
9use serde::{Deserialize, Serialize};
10use thiserror::Error;
11
12/// Represents a regular bag expression error.
13#[derive(Clone, Debug, Error, Eq, PartialEq, Serialize, Deserialize)]
14pub enum RbeError<K, V, R>
15where
16    K: Key,
17    V: Value,
18    R: Ref,
19{
20    #[error("Symbol {x} doesn't match with empty. Open: {open}")]
21    UnexpectedEmpty { x: K, open: bool },
22
23    #[error("Symbol {x} doesn't match with expected symbol {expected}. Open: {open}")]
24    UnexpectedSymbol { x: K, expected: K, open: bool },
25
26    #[error("Max cardinality 0, but found symbol {x}")]
27    MaxCardinalityZeroFoundValue { x: K },
28
29    // TODO: Maybe this error is redundant?
30    #[error("Negative lower bound: {min}")]
31    RangeNegativeLowerBound { min: usize },
32
33    #[error("Min > Max in cardinality {card} for {symbol}")]
34    RangeLowerBoundBiggerMax { symbol: K, card: Cardinality },
35
36    #[error("Min > Max in cardinality {card} for {expr}")]
37    RangeLowerBoundBiggerMaxExpr {
38        expr: Box<Rbe<K, V, R>>,
39        card: Cardinality,
40    },
41
42    #[error("Derived expr: {non_nullable_rbe} is not nullable\nExpr {expr}")]
43    NonNullableMatch {
44        non_nullable_rbe: Box<Rbe<K, V, R>>,
45        expr: Box<Rbe<K, V, R>>,
46    },
47
48    #[error("Cardinality failed for symbol {symbol}. Current number: {current_number}, expected cardinality: {expected_cardinality}")]
49    CardinalityFail {
50        symbol: K,
51        expected_cardinality: Cardinality,
52        current_number: usize,
53    },
54
55    #[error("Cardinality failed for expr. Current number: {current_number}, expected cardinality: {expected_cardinality}")]
56    CardinalityFailRepeat {
57        expected_cardinality: Cardinality,
58        current_number: usize,
59    },
60
61    #[error("Cardinality(0,0) but found symbol after derivative")]
62    CardinalityZeroZeroDeriv { symbol: K },
63
64    #[error("Should fail but passed: {name}")]
65    ShouldFailButPassed { name: String },
66
67    #[error("Or values failed {e}\n {failures}")]
68    OrValuesFail {
69        e: Box<Rbe<K, V, R>>,
70        failures: Failures<K, V, R>,
71    },
72
73    #[error("All values in or branch failed")]
74    MkOrValuesFail,
75
76    #[error("Error matching iterator: {error_msg}\nExpr: {expr}\nCurrent:{current}\nkey: {key}\nopen: {open}")]
77    DerivIterError {
78        error_msg: String,
79        processed: Vec<(K, V)>,
80        expr: Box<Rbe<K, V, R>>,
81        current: Box<Rbe<K, V, R>>,
82        key: K,
83        open: bool,
84    },
85
86    #[error("{msg}")]
87    MsgError { msg: String },
88
89    #[error("Empty candidates for: \nRegular expression: {rbe}\nValues:{values}")]
90    EmptyCandidates {
91        rbe: Box<Rbe<K, V, R>>,
92        values: Values<K, V>,
93    },
94
95    #[error("RbeTable: Key {key} has no component associated. Available keys: {available_keys}")]
96    RbeTableKeyWithoutComponent { key: K, available_keys: Keys<K> },
97}