postgrest_parser/error/
parse.rs1use thiserror::Error;
2
3#[derive(Error, Debug, PartialEq, Clone)]
4pub enum ParseError {
5 #[error("unknown operator: {0}")]
6 UnknownOperator(String),
7
8 #[error("invalid filter format: {0}")]
9 InvalidFilterFormat(String),
10
11 #[error("invalid operator: {0}")]
12 InvalidOperator(String),
13
14 #[error("expected operator: {0}")]
15 ExpectedOperator(String),
16
17 #[error("missing operator or value")]
18 MissingOperatorOrValue,
19
20 #[error("invalid quantifier: {0}")]
21 InvalidQuantifier(String),
22
23 #[error("operator does not support quantifiers")]
24 QuantifierNotSupported,
25
26 #[error("invalid FTS language: {0}")]
27 InvalidFtsLanguage(String),
28
29 #[error("expected list format: {0}")]
30 ExpectedListFormat(String),
31
32 #[error("unclosed parenthesis")]
33 UnclosedParenthesis,
34
35 #[error("unexpected closing parenthesis")]
36 UnexpectedClosingParenthesis,
37
38 #[error("invalid field name: {0}")]
39 InvalidFieldName(String),
40
41 #[error("empty field name")]
42 EmptyFieldName,
43
44 #[error("invalid JSON path syntax")]
45 InvalidJsonPathSyntax,
46
47 #[error("invalid type cast: {0}")]
48 InvalidTypeCast(String),
49
50 #[error("invalid select item: {0}")]
51 InvalidSelectItem(String),
52
53 #[error("unexpected '(' after field")]
54 UnexpectedParenthesisAfterField,
55
56 #[error("expected '(' after relation name")]
57 ExpectedParenthesisAfterRelation,
58
59 #[error("unclosed parenthesis in select")]
60 UnclosedParenthesisInSelect,
61
62 #[error("unexpected token: {0}")]
63 UnexpectedToken(String),
64
65 #[error("unexpected token in nested select")]
66 UnexpectedTokenInNestedSelect,
67
68 #[error("invalid order options: {0}")]
69 InvalidOrderOptions(String),
70
71 #[error("invalid logic expression: {0}")]
72 InvalidLogicExpression(String),
73
74 #[error("logic expression must be wrapped in parentheses")]
75 LogicExpressionNotWrapped,
76
77 #[error("invalid nulls option: {0}")]
78 InvalidNullsOption(String),
79
80 #[error("invalid direction: {0}")]
81 InvalidDirection(String),
82
83 #[error("invalid limit value: {0}")]
84 InvalidLimit(String),
85
86 #[error("invalid offset value: {0}")]
87 InvalidOffset(String),
88
89 #[error("invalid integer value: {0}")]
90 InvalidInteger(String),
91
92 #[error("reserved key: {0}")]
93 ReservedKey(String),
94
95 #[error("invalid JSON body: {0}")]
97 InvalidJsonBody(String),
98
99 #[error("invalid insert body: {0}")]
100 InvalidInsertBody(String),
101
102 #[error("empty update body")]
103 EmptyUpdateBody,
104
105 #[error("invalid update body: {0}")]
106 InvalidUpdateBody(String),
107
108 #[error("invalid on_conflict specification: {0}")]
109 InvalidOnConflict(String),
110
111 #[error("unsupported HTTP method: {0}")]
112 UnsupportedMethod(String),
113
114 #[error("invalid schema name: {0}")]
115 InvalidSchema(String),
116
117 #[error("invalid table name: {0}")]
118 InvalidTableName(String),
119}
120
121#[cfg(test)]
122mod tests {
123 use super::*;
124
125 #[test]
126 fn test_parse_error_unknown_operator() {
127 let err = ParseError::UnknownOperator("invalid".to_string());
128 assert!(err.to_string().contains("unknown operator"));
129 }
130
131 #[test]
132 fn test_parse_error_unclosed_parenthesis() {
133 let err = ParseError::UnclosedParenthesis;
134 assert!(err.to_string().contains("unclosed"));
135 }
136
137 #[test]
138 fn test_parse_error_eq() {
139 let err1 = ParseError::UnknownOperator("test".to_string());
140 let err2 = ParseError::UnknownOperator("test".to_string());
141 assert_eq!(err1, err2);
142 }
143
144 #[test]
145 fn test_parse_error_clone() {
146 let err = ParseError::UnclosedParenthesis;
147 let cloned = err.clone();
148 assert_eq!(err, cloned);
149 }
150}