Skip to main content

uni_query/query/rewrite/
error.rs

1/// Error types for query rewriting operations
2use std::fmt;
3
4/// Errors that can occur during query rewriting
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub enum RewriteError {
7    /// Function has wrong number of arguments
8    ArityMismatch { expected: usize, got: usize },
9
10    /// Function argument arity is out of expected range
11    ArityOutOfRange { min: usize, max: usize, got: usize },
12
13    /// Expected a string literal for property name but got dynamic expression
14    ExpectedStringLiteral { arg_index: usize },
15
16    /// Expected an entity reference (variable) but got different type
17    ExpectedEntityReference { arg_index: usize },
18
19    /// Argument has unexpected type
20    TypeError {
21        arg_index: usize,
22        expected: String,
23        got: String,
24    },
25
26    /// Rewrite rule is not applicable in current context
27    NotApplicable { reason: String },
28
29    /// Internal error during rewrite transformation
30    TransformError { message: String },
31
32    /// Missing required context information
33    MissingContext { required: String },
34}
35
36impl fmt::Display for RewriteError {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            RewriteError::ArityMismatch { expected, got } => {
40                write!(
41                    f,
42                    "Function arity mismatch: expected {} arguments, got {}",
43                    expected, got
44                )
45            }
46            RewriteError::ArityOutOfRange { min, max, got } => {
47                write!(
48                    f,
49                    "Function arity out of range: expected {}-{} arguments, got {}",
50                    min, max, got
51                )
52            }
53            RewriteError::ExpectedStringLiteral { arg_index } => {
54                write!(
55                    f,
56                    "Expected string literal at argument {}, got dynamic expression",
57                    arg_index
58                )
59            }
60            RewriteError::ExpectedEntityReference { arg_index } => {
61                write!(
62                    f,
63                    "Expected entity reference at argument {}, got different type",
64                    arg_index
65                )
66            }
67            RewriteError::TypeError {
68                arg_index,
69                expected,
70                got,
71            } => {
72                write!(
73                    f,
74                    "Type error at argument {}: expected {}, got {}",
75                    arg_index, expected, got
76                )
77            }
78            RewriteError::NotApplicable { reason } => {
79                write!(f, "Rewrite not applicable: {}", reason)
80            }
81            RewriteError::TransformError { message } => {
82                write!(f, "Transform error: {}", message)
83            }
84            RewriteError::MissingContext { required } => {
85                write!(f, "Missing required context: {}", required)
86            }
87        }
88    }
89}
90
91impl std::error::Error for RewriteError {}