rust_rule_engine/
errors.rs

1use thiserror::Error;
2
3/// Error types that can occur in the rule engine
4#[derive(Error, Debug)]
5pub enum RuleEngineError {
6    /// Parse error during rule parsing
7    #[error("Parse error: {message}")]
8    ParseError {
9        /// Error message
10        message: String,
11    },
12
13    /// Error during rule evaluation
14    #[error("Evaluation error: {message}")]
15    EvaluationError {
16        /// Error message
17        message: String,
18    },
19
20    /// Field not found in data context
21    #[error("Field not found: {field}")]
22    FieldNotFound {
23        /// Field name that was not found
24        field: String,
25    },
26
27    /// IO error for file operations
28    #[error("IO error: {0}")]
29    IoError(#[from] std::io::Error),
30
31    /// Type mismatch error
32    #[error("Type mismatch: expected {expected}, got {actual}")]
33    TypeMismatch {
34        /// Expected type
35        expected: String,
36        /// Actual type
37        actual: String,
38    },
39
40    /// Invalid operator error
41    #[error("Invalid operator: {operator}")]
42    InvalidOperator {
43        /// Invalid operator
44        operator: String,
45    },
46
47    /// Invalid logical operator error
48    #[error("Invalid logical operator: {operator}")]
49    InvalidLogicalOperator {
50        /// Invalid logical operator
51        operator: String,
52    },
53
54    /// Regex compilation or execution error
55    #[error("Regex error: {message}")]
56    RegexError {
57        /// Error message
58        message: String,
59    },
60
61    /// Action execution error
62    #[error("Action execution error: {message}")]
63    ActionError {
64        /// Error message
65        message: String,
66    },
67
68    /// General execution error
69    #[error("Execution error: {0}")]
70    ExecutionError(String),
71
72    /// Serialization/deserialization error
73    #[error("Serialization error: {message}")]
74    SerializationError {
75        /// Error message
76        message: String,
77    },
78}
79
80/// Convenient Result type alias for rule engine operations
81pub type Result<T> = std::result::Result<T, RuleEngineError>;