condition_matcher/
error.rs

1use std::fmt;
2
3/// Errors that can occur during condition matching
4#[derive(Debug, Clone, PartialEq)]
5pub enum MatchError {
6    /// The specified field was not found on the type
7    FieldNotFound {
8        field: String,
9        type_name: String,
10    },
11    /// Type mismatch between expected and actual values
12    TypeMismatch {
13        field: String,
14        expected: String,
15        actual: String,
16    },
17    /// The operator is not supported for this type/context
18    UnsupportedOperator {
19        operator: String,
20        context: String,
21    },
22    /// Length check is not supported for this type
23    LengthNotSupported {
24        type_name: String,
25    },
26    /// Regex compilation failed
27    #[cfg(feature = "regex")]
28    RegexError {
29        pattern: String,
30        message: String,
31    },
32    /// The field path is empty
33    EmptyFieldPath,
34    /// Nested field not found
35    NestedFieldNotFound {
36        path: Vec<String>,
37        failed_at: String,
38    },
39}
40
41impl fmt::Display for MatchError {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        match self {
44            MatchError::FieldNotFound { field, type_name } => {
45                write!(f, "Field '{}' not found on type '{}'", field, type_name)
46            }
47            MatchError::TypeMismatch { field, expected, actual } => {
48                write!(f, "Type mismatch for field '{}': expected '{}', got '{}'", field, expected, actual)
49            }
50            MatchError::UnsupportedOperator { operator, context } => {
51                write!(f, "Operator '{}' not supported for {}", operator, context)
52            }
53            MatchError::LengthNotSupported { type_name } => {
54                write!(f, "Length check not supported for type '{}'", type_name)
55            }
56            #[cfg(feature = "regex")]
57            MatchError::RegexError { pattern, message } => {
58                write!(f, "Invalid regex pattern '{}': {}", pattern, message)
59            }
60            MatchError::EmptyFieldPath => {
61                write!(f, "Field path cannot be empty")
62            }
63            MatchError::NestedFieldNotFound { path, failed_at } => {
64                write!(f, "Nested field not found at '{}' in path {:?}", failed_at, path)
65            }
66        }
67    }
68}
69
70impl std::error::Error for MatchError {}