gqlite 1.1.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/gqliterb/.cargo/config.toml +2 -0
- data/ext/gqliterb/Cargo.lock +1109 -0
- data/ext/gqliterb/Cargo.toml +43 -0
- data/ext/gqliterb/extconf.rb +4 -0
- data/ext/gqliterb/src/lib.rs +260 -0
- data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +2060 -0
- data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +132 -0
- data/ext/gqliterb/vendor/gqlitedb/askama.toml +3 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/mod.rs +25 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/common/pokec.rs +185 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_divan.rs +137 -0
- data/ext/gqliterb/vendor/gqlitedb/benches/pokec_iai.rs +122 -0
- data/ext/gqliterb/vendor/gqlitedb/release.toml +7 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/arithmetic.rs +96 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/containers.rs +33 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/count.rs +35 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators/stats.rs +168 -0
- data/ext/gqliterb/vendor/gqlitedb/src/aggregators.rs +74 -0
- data/ext/gqliterb/vendor/gqlitedb/src/capi.rs +236 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/expression_analyser.rs +427 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler/variables_manager.rs +620 -0
- data/ext/gqliterb/vendor/gqlitedb/src/compiler.rs +1106 -0
- data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +208 -0
- data/ext/gqliterb/vendor/gqlitedb/src/consts.rs +10 -0
- data/ext/gqliterb/vendor/gqlitedb/src/error.rs +621 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/containers.rs +115 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/edge.rs +20 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/math.rs +44 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/node.rs +16 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +48 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/scalar.rs +86 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/string.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions/value.rs +99 -0
- data/ext/gqliterb/vendor/gqlitedb/src/functions.rs +412 -0
- data/ext/gqliterb/vendor/gqlitedb/src/graph.rs +268 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/evaluators.rs +1788 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/instructions.rs +262 -0
- data/ext/gqliterb/vendor/gqlitedb/src/interpreter/mod.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/lib.rs +42 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/ast.rs +625 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/gql.pest +191 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser/parser.rs +1153 -0
- data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +4 -0
- data/ext/gqliterb/vendor/gqlitedb/src/prelude.rs +8 -0
- data/ext/gqliterb/vendor/gqlitedb/src/serialize_with.rs +94 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/pgql.rs +121 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/redb.rs +1250 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store/sqlite.rs +994 -0
- data/ext/gqliterb/vendor/gqlitedb/src/store.rs +432 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/compiler.rs +92 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/evaluators.rs +227 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/parser.rs +81 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/redb.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store/sqlite.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/store.rs +462 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/ast.rs +356 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/programs.rs +455 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests/templates.rs +2 -0
- data/ext/gqliterb/vendor/gqlitedb/src/tests.rs +39 -0
- data/ext/gqliterb/vendor/gqlitedb/src/utils.rs +28 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/compare.rs +212 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/contains.rs +47 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value/value_map.rs +298 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value.rs +559 -0
- data/ext/gqliterb/vendor/gqlitedb/src/value_table.rs +616 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/call_stats.sql +22 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_count_for_node.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_create.sql +6 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete_by_nodes.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_select.sql +139 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_create.sql +16 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_delete.sql +3 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_create_table.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_get.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_set.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_create.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_delete.sql +1 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_select.sql +42 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_update.sql +4 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/table_exists.sql +5 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_from_1_01.sql +2 -0
- data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_graph_from_1_01.sql +65 -0
- data/lib/gqlite.rb +1 -75
- metadata +118 -25
- data/ext/gqlite/extconf.rb +0 -21
- data/ext/gqlite/gqlite-amalgamate.cpp +0 -9599
- data/ext/gqlite/gqlite-c.h +0 -95
- data/ext/gqlite/gqlite.h +0 -141
@@ -0,0 +1,621 @@
|
|
1
|
+
//! Errors used for gqlite.
|
2
|
+
use crate::prelude::*;
|
3
|
+
|
4
|
+
/// Represent compile time errors.
|
5
|
+
#[derive(thiserror::Error, Debug)]
|
6
|
+
#[allow(missing_docs)]
|
7
|
+
#[non_exhaustive]
|
8
|
+
pub enum CompileTimeError
|
9
|
+
{
|
10
|
+
/// Floating point overflow
|
11
|
+
#[error("FloatingPointOverflow: '{text}' is too large.")]
|
12
|
+
FloatingPointOverflow
|
13
|
+
{
|
14
|
+
text: String
|
15
|
+
},
|
16
|
+
/// Integer overflow
|
17
|
+
#[error("IntegerOverflow: '{text}' is too large.")]
|
18
|
+
IntegerOverflow
|
19
|
+
{
|
20
|
+
text: String
|
21
|
+
},
|
22
|
+
/// Parse error
|
23
|
+
#[error("ParseError: '{0}'")]
|
24
|
+
ParseError(#[from] pest::error::Error<crate::parser::parser::Rule>),
|
25
|
+
/// Variable is not defined
|
26
|
+
#[error("UndefinedVariable: Unknown variable '{name}'.")]
|
27
|
+
UndefinedVariable
|
28
|
+
{
|
29
|
+
name: String
|
30
|
+
},
|
31
|
+
/// This error happens if the variable is already defined
|
32
|
+
#[error("VariableAlreadyBound: Variable '{name}' is already bound.")]
|
33
|
+
VariableAlreadyBound
|
34
|
+
{
|
35
|
+
name: String
|
36
|
+
},
|
37
|
+
/// This error happens if the variable is already bound to a different type
|
38
|
+
#[error(
|
39
|
+
"VariableTypeConflict: Variable '{name}' is redefined as a variable of a different type."
|
40
|
+
)]
|
41
|
+
VariableTypeConflict
|
42
|
+
{
|
43
|
+
name: String
|
44
|
+
},
|
45
|
+
/// ()-[]-() is not accepted in this context
|
46
|
+
#[error("RequiresDirectedRelationship: edges need to be directed in this context: '{context}'.")]
|
47
|
+
RequiresDirectedRelationship
|
48
|
+
{
|
49
|
+
context: &'static str
|
50
|
+
},
|
51
|
+
#[error("NoSingleRelationshipType: an edge type need to be specified.")]
|
52
|
+
NoSingleRelationshipType,
|
53
|
+
#[error("NotComparable: values are not comparable.")]
|
54
|
+
NotComparable,
|
55
|
+
#[error("UnknownFunction: {name}")]
|
56
|
+
UnknownFunction
|
57
|
+
{
|
58
|
+
name: String
|
59
|
+
},
|
60
|
+
#[error("InvalidAggregation: aggregation is not accepted in this expression.")]
|
61
|
+
InvalidAggregation,
|
62
|
+
#[error("ColumnNameConflict: Column '{name}' is duplicated.")]
|
63
|
+
ColumnNameConflict
|
64
|
+
{
|
65
|
+
name: String
|
66
|
+
},
|
67
|
+
#[error("InvalidDelete: invalid delete argument, expected node or edge.")]
|
68
|
+
InvalidDelete,
|
69
|
+
/// Too few or too many arguments
|
70
|
+
#[error("InvalidNumberOfArguments: Invalid number of arguments for function '{function_name}' got {got} expected {expected}.")]
|
71
|
+
InvalidNumberOfArguments
|
72
|
+
{
|
73
|
+
function_name: &'static str,
|
74
|
+
got: usize,
|
75
|
+
expected: usize,
|
76
|
+
},
|
77
|
+
#[error("NonConstantExpression: statement expect a constant expression.")]
|
78
|
+
NonConstantExpression,
|
79
|
+
#[error("InvalidArgumentType: invalid argument type.")]
|
80
|
+
InvalidArgumentType,
|
81
|
+
}
|
82
|
+
|
83
|
+
/// Runtime errors.
|
84
|
+
#[derive(thiserror::Error, Debug)]
|
85
|
+
#[allow(missing_docs)]
|
86
|
+
#[non_exhaustive]
|
87
|
+
pub enum RunTimeError
|
88
|
+
{
|
89
|
+
/// Parameter is not known
|
90
|
+
#[error("UnknownParameter: Unknown parameter '{name}'.")]
|
91
|
+
UnknownParameter
|
92
|
+
{
|
93
|
+
name: String
|
94
|
+
},
|
95
|
+
/// Too few or too many arguments
|
96
|
+
#[error("InvalidNumberOfArguments: Invalid number of arguments for function '{function_name}' got {got} expected {expected}.")]
|
97
|
+
InvalidNumberOfArguments
|
98
|
+
{
|
99
|
+
function_name: &'static str,
|
100
|
+
got: usize,
|
101
|
+
expected: usize,
|
102
|
+
},
|
103
|
+
/// Parameter is not known
|
104
|
+
#[error(
|
105
|
+
"InvalidArgument: Function '{function_name}' expected argument {index} of type {expected_type} but got {value}."
|
106
|
+
)]
|
107
|
+
InvalidArgument
|
108
|
+
{
|
109
|
+
function_name: &'static str,
|
110
|
+
index: usize,
|
111
|
+
expected_type: &'static str,
|
112
|
+
value: String,
|
113
|
+
},
|
114
|
+
#[error(
|
115
|
+
"MapElementAccessByNonString: attempt to accessing a map value using a non-string value."
|
116
|
+
)]
|
117
|
+
MapElementAccessByNonString,
|
118
|
+
#[error("NotComparable: values are not comparable.")]
|
119
|
+
NotComparable,
|
120
|
+
/// Edge has no label
|
121
|
+
#[error("MissingEdgeLabel")]
|
122
|
+
MissingEdgeLabel,
|
123
|
+
#[error("UnknownFunction: {name}")]
|
124
|
+
UnknownFunction
|
125
|
+
{
|
126
|
+
name: String
|
127
|
+
},
|
128
|
+
#[error("InvalidBinaryOperands: operands for binary operation are not compatible.")]
|
129
|
+
InvalidBinaryOperands,
|
130
|
+
#[error("InvalidNegationOperands: operands for negation operation are not compatible.")]
|
131
|
+
InvalidNegationOperands,
|
132
|
+
#[error("InvalidDelete: invalid delete argument, expected node or edge.")]
|
133
|
+
InvalidDelete,
|
134
|
+
#[error("DeleteConnectedNode: node is still connected and cannot be deleted.")]
|
135
|
+
DeleteConnectedNode,
|
136
|
+
#[error("NegativeIntegerArgument: statement expect a positive integer.")]
|
137
|
+
NegativeIntegerArgument,
|
138
|
+
#[error("InvalidArgumentType: invalid argument type.")]
|
139
|
+
InvalidArgumentType,
|
140
|
+
#[error("OutOfBound: index is out of bound for array.")]
|
141
|
+
OutOfBound,
|
142
|
+
#[error("DuplicatedGraph: {graph_name} already exists.")]
|
143
|
+
DuplicatedGraph
|
144
|
+
{
|
145
|
+
graph_name: String
|
146
|
+
},
|
147
|
+
#[error("UnknownGraph: {graph_name} does not exists.")]
|
148
|
+
UnknownGraph
|
149
|
+
{
|
150
|
+
graph_name: String
|
151
|
+
},
|
152
|
+
}
|
153
|
+
|
154
|
+
/// Internal errors, should be treated as bugs.
|
155
|
+
#[derive(thiserror::Error, Debug)]
|
156
|
+
#[non_exhaustive]
|
157
|
+
pub enum InternalError
|
158
|
+
{
|
159
|
+
#[error("Aggregation state is missing.")]
|
160
|
+
MissingAggregationState,
|
161
|
+
#[error("Aggregation is missing an argument.")]
|
162
|
+
MissingAggregationArgument,
|
163
|
+
#[error("Aggregations are missing.")]
|
164
|
+
MissingAggregations,
|
165
|
+
#[error("Expected a value to be a node in {context}.")]
|
166
|
+
ExpectedNode
|
167
|
+
{
|
168
|
+
context: &'static str
|
169
|
+
},
|
170
|
+
#[error("Expected a value to be an edge in {context}.")]
|
171
|
+
ExpectedEdge
|
172
|
+
{
|
173
|
+
context: &'static str
|
174
|
+
},
|
175
|
+
#[error("Missing a pair from pest parsing in {context}.")]
|
176
|
+
MissingPair
|
177
|
+
{
|
178
|
+
context: &'static str
|
179
|
+
},
|
180
|
+
#[error("Unexpected pair {pair} from pest parsing in {context}.")]
|
181
|
+
UnexpectedPair
|
182
|
+
{
|
183
|
+
context: &'static str, pair: String
|
184
|
+
},
|
185
|
+
#[error("Missing value from stack in {context}.")]
|
186
|
+
MissingStackValue
|
187
|
+
{
|
188
|
+
context: &'static str
|
189
|
+
},
|
190
|
+
#[error("Path pattern was used in create expression in {context}.")]
|
191
|
+
PathPatternInCreateExpression
|
192
|
+
{
|
193
|
+
context: &'static str
|
194
|
+
},
|
195
|
+
#[error("Invalid create labels expression {context}.")]
|
196
|
+
InvalidCreateLabels
|
197
|
+
{
|
198
|
+
context: &'static str
|
199
|
+
},
|
200
|
+
#[error("Expected graph value {context}.")]
|
201
|
+
ExpectedGraphValue
|
202
|
+
{
|
203
|
+
context: &'static str
|
204
|
+
},
|
205
|
+
#[error("Expected node query {context}.")]
|
206
|
+
ExpectedNodeQuery
|
207
|
+
{
|
208
|
+
context: &'static str
|
209
|
+
},
|
210
|
+
#[error("Expected edge query {context}.")]
|
211
|
+
ExpectedEdgeQuery
|
212
|
+
{
|
213
|
+
context: &'static str
|
214
|
+
},
|
215
|
+
#[error("Empty stack.")]
|
216
|
+
EmptyStack,
|
217
|
+
#[error("Invalid value cast, cannot cast {value} to {typename}.")]
|
218
|
+
InvalidValueCast
|
219
|
+
{
|
220
|
+
value: crate::Value,
|
221
|
+
typename: &'static str,
|
222
|
+
},
|
223
|
+
#[error("Code is not reachable in {context}.")]
|
224
|
+
Unreachable
|
225
|
+
{
|
226
|
+
context: &'static str
|
227
|
+
},
|
228
|
+
#[error("Invalid number of columns in row {actual} but expected {expected}.")]
|
229
|
+
InvalidNumberColumns
|
230
|
+
{
|
231
|
+
actual: usize, expected: usize
|
232
|
+
},
|
233
|
+
#[error("Unknown variable '{name}'.")]
|
234
|
+
UnknownVariable
|
235
|
+
{
|
236
|
+
name: String
|
237
|
+
},
|
238
|
+
#[error("Invalid index {index} access of a vector of length {length}.")]
|
239
|
+
InvalidIndex
|
240
|
+
{
|
241
|
+
index: usize, length: usize
|
242
|
+
},
|
243
|
+
#[error("Invalid row length got {got} expected {expected}.")]
|
244
|
+
InvalidRowLength
|
245
|
+
{
|
246
|
+
got: usize, expected: usize
|
247
|
+
},
|
248
|
+
#[error("Some variables were declared, but not set. Set variables are {set_variables:?}, all variables are {all_variables:?}")]
|
249
|
+
NotAllVariablesAreSet
|
250
|
+
{
|
251
|
+
set_variables: Vec<String>,
|
252
|
+
all_variables: Vec<String>,
|
253
|
+
},
|
254
|
+
#[error("A generic error occured {0}.")]
|
255
|
+
GenericStdError(#[from] Box<dyn std::error::Error + Sync + Send>),
|
256
|
+
#[error("Not a write transaction")]
|
257
|
+
NotWriteTransaction,
|
258
|
+
#[error("Missing metadata {key}")]
|
259
|
+
MissingMetadata
|
260
|
+
{
|
261
|
+
key: String
|
262
|
+
},
|
263
|
+
#[error("Invalid aggregation state")]
|
264
|
+
InvalidAggregationState,
|
265
|
+
|
266
|
+
// Third-party
|
267
|
+
#[error("Missing element in iterator.")]
|
268
|
+
MissingElementIterator,
|
269
|
+
|
270
|
+
#[cfg(feature = "redb")]
|
271
|
+
#[error("redb: {0}")]
|
272
|
+
RedbError(#[from] redb::Error),
|
273
|
+
|
274
|
+
// Errors from sqlite
|
275
|
+
#[cfg(feature = "sqlite")]
|
276
|
+
#[error("Sqlite: {0}")]
|
277
|
+
SqliteError(#[from] rusqlite::Error),
|
278
|
+
|
279
|
+
// Errors from askama
|
280
|
+
#[cfg(feature = "sqlite")]
|
281
|
+
#[error("Askama: {0}")]
|
282
|
+
AskamaError(#[from] askama::Error),
|
283
|
+
|
284
|
+
// Serialization errors
|
285
|
+
#[error("An error occured while serialization to Cbor: {0}")]
|
286
|
+
CborSerialisationError(#[from] ciborium::ser::Error<std::io::Error>),
|
287
|
+
#[error("An error occured while deserialization from Cbor: {0}")]
|
288
|
+
CborDeserialisationError(#[from] ciborium::de::Error<std::io::Error>),
|
289
|
+
#[error("JSon error: {0}")]
|
290
|
+
JsonError(#[from] serde_json::Error),
|
291
|
+
|
292
|
+
// Parser related error
|
293
|
+
#[error("Missing function name")]
|
294
|
+
MissingFunctionName,
|
295
|
+
#[error("Unexpected expression from the parser: {1} in {0}")]
|
296
|
+
UnxpectedExpression(&'static str, String),
|
297
|
+
|
298
|
+
// Technical debt: following errors need to be reviewed
|
299
|
+
#[error("Parse int error: {0}")]
|
300
|
+
ParseFloatError(#[from] std::num::ParseFloatError),
|
301
|
+
#[error("Parse int error: {0}")]
|
302
|
+
ParseIntError(#[from] std::num::ParseIntError),
|
303
|
+
#[error("Unknown node")]
|
304
|
+
UnknownNode,
|
305
|
+
#[error("Unknown edge")]
|
306
|
+
UnknownEdge,
|
307
|
+
#[error("Unimplemented error at {0}")]
|
308
|
+
Unimplemented(&'static str),
|
309
|
+
#[error("Infallible.")]
|
310
|
+
Infallible(#[from] std::convert::Infallible),
|
311
|
+
#[error("Poison error {0}.")]
|
312
|
+
Poison(String),
|
313
|
+
}
|
314
|
+
|
315
|
+
/// Error in the store backend.
|
316
|
+
#[derive(thiserror::Error, Debug)]
|
317
|
+
#[allow(missing_docs)]
|
318
|
+
#[non_exhaustive]
|
319
|
+
pub enum StoreError
|
320
|
+
{
|
321
|
+
#[error("UnknownBackend: backend '{backend}' is unknown.")]
|
322
|
+
UnknownBackend
|
323
|
+
{
|
324
|
+
backend: String
|
325
|
+
},
|
326
|
+
#[error("UnavailableBackend: backend '{backend}' is unavailable, and was not built.")]
|
327
|
+
UnavailableBackend
|
328
|
+
{
|
329
|
+
backend: &'static str
|
330
|
+
},
|
331
|
+
#[error("OpeningError: could not open database, got the following error messages from the backends: {errors}.")]
|
332
|
+
OpeningError
|
333
|
+
{
|
334
|
+
errors: String
|
335
|
+
},
|
336
|
+
#[error("DuplicatedGraph: attempt at creating an existing graph: {graph_name}.")]
|
337
|
+
DuplicatedGraph
|
338
|
+
{
|
339
|
+
graph_name: String
|
340
|
+
},
|
341
|
+
#[error("UnknownGraph: {graph_name} is not known.")]
|
342
|
+
UnknownGraph
|
343
|
+
{
|
344
|
+
graph_name: String
|
345
|
+
},
|
346
|
+
#[error(
|
347
|
+
"IncompatibleVersion: could not open database, got version {actual} but expected {expected}."
|
348
|
+
)]
|
349
|
+
IncompatibleVersion
|
350
|
+
{
|
351
|
+
actual: utils::Version,
|
352
|
+
expected: utils::Version,
|
353
|
+
},
|
354
|
+
}
|
355
|
+
|
356
|
+
/// GQLite errors
|
357
|
+
#[derive(thiserror::Error, Debug)]
|
358
|
+
#[non_exhaustive]
|
359
|
+
pub enum Error
|
360
|
+
{
|
361
|
+
/// Error that occurs during compilation
|
362
|
+
#[error("CompileTime: {0}")]
|
363
|
+
CompileTime(#[from] CompileTimeError),
|
364
|
+
/// Error that occurs during runtime
|
365
|
+
#[error("RunTime: {0}")]
|
366
|
+
RunTime(#[from] RunTimeError),
|
367
|
+
/// Store error
|
368
|
+
#[error("StoreError: {0}")]
|
369
|
+
StoreError(#[from] StoreError),
|
370
|
+
/// Error that should not occurs and most likely correspond to a bug
|
371
|
+
#[error("Internal: {0}")]
|
372
|
+
Internal(#[from] InternalError),
|
373
|
+
}
|
374
|
+
|
375
|
+
fn assert_send_sync<T: Send + Sync>() {}
|
376
|
+
fn _check_error_send_sync()
|
377
|
+
{
|
378
|
+
assert_send_sync::<Error>();
|
379
|
+
}
|
380
|
+
|
381
|
+
impl Error
|
382
|
+
{
|
383
|
+
/// Return the underlying error (match WithBacktrace API)
|
384
|
+
pub fn error(&self) -> &Error
|
385
|
+
{
|
386
|
+
self
|
387
|
+
}
|
388
|
+
pub(crate) fn split_error(self) -> (Error, ())
|
389
|
+
{
|
390
|
+
(self, ())
|
391
|
+
}
|
392
|
+
pub(crate) fn make_error(error: Error, _: ()) -> Error
|
393
|
+
{
|
394
|
+
error
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
// _____ __ ___ _ _ ____ _ _
|
399
|
+
// | ____|_ __ _ __ ___ _ _\ \ / (_) |_| |__ | __ ) __ _ ___| | __ |_ _ __ __ _ ___ ___
|
400
|
+
// | _| | '__| '__/ _ \| '__\ \ /\ / /| | __| '_ \| _ \ / _` |/ __| |/ / __| '__/ _` |/ __/ _ \
|
401
|
+
// | |___| | | | | (_) | | \ V V / | | |_| | | | |_) | (_| | (__| <| |_| | | (_| | (_| __/
|
402
|
+
// |_____|_| |_| \___/|_| \_/\_/ |_|\__|_| |_|____/ \__,_|\___|_|\_\\__|_| \__,_|\___\___|
|
403
|
+
|
404
|
+
#[derive(Debug)]
|
405
|
+
pub struct ErrorWithBacktrace
|
406
|
+
{
|
407
|
+
error: Error,
|
408
|
+
backtrace: std::backtrace::Backtrace,
|
409
|
+
}
|
410
|
+
|
411
|
+
impl ErrorWithBacktrace
|
412
|
+
{
|
413
|
+
/// Return the underlying error
|
414
|
+
pub fn error(&self) -> &Error
|
415
|
+
{
|
416
|
+
&self.error
|
417
|
+
}
|
418
|
+
pub(crate) fn split_error(self) -> (Error, std::backtrace::Backtrace)
|
419
|
+
{
|
420
|
+
(self.error, self.backtrace)
|
421
|
+
}
|
422
|
+
pub(crate) fn make_error(error: Error, backtrace: std::backtrace::Backtrace) -> Self
|
423
|
+
{
|
424
|
+
Self { error, backtrace }
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
impl std::fmt::Display for ErrorWithBacktrace
|
429
|
+
{
|
430
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
|
431
|
+
{
|
432
|
+
self.error.fmt(f)
|
433
|
+
}
|
434
|
+
}
|
435
|
+
impl<T> From<T> for ErrorWithBacktrace
|
436
|
+
where
|
437
|
+
T: Into<Error>,
|
438
|
+
{
|
439
|
+
fn from(value: T) -> Self
|
440
|
+
{
|
441
|
+
Self {
|
442
|
+
error: value.into(),
|
443
|
+
backtrace: std::backtrace::Backtrace::capture(),
|
444
|
+
}
|
445
|
+
}
|
446
|
+
}
|
447
|
+
|
448
|
+
// ____ _
|
449
|
+
// / ___|___ _ ____ _____ _ __ ___(_) ___ _ __
|
450
|
+
// | | / _ \| '_ \ \ / / _ \ '__/ __| |/ _ \| '_ \
|
451
|
+
// | |__| (_) | | | \ V / __/ | \__ \ | (_) | | | |
|
452
|
+
// \____\___/|_| |_|\_/ \___|_| |___/_|\___/|_| |_|
|
453
|
+
|
454
|
+
impl<T> From<std::sync::PoisonError<T>> for Error
|
455
|
+
{
|
456
|
+
fn from(value: std::sync::PoisonError<T>) -> Self
|
457
|
+
{
|
458
|
+
InternalError::Poison(format!("{:?}", value)).into()
|
459
|
+
}
|
460
|
+
}
|
461
|
+
|
462
|
+
impl From<pest::error::Error<crate::parser::parser::Rule>> for Error
|
463
|
+
{
|
464
|
+
fn from(value: pest::error::Error<crate::parser::parser::Rule>) -> Self
|
465
|
+
{
|
466
|
+
CompileTimeError::from(value).into()
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
macro_rules! error_as_internal {
|
471
|
+
($err_type:ty) => {
|
472
|
+
impl From<$err_type> for crate::prelude::ErrorType
|
473
|
+
{
|
474
|
+
fn from(value: $err_type) -> Self
|
475
|
+
{
|
476
|
+
let err: crate::error::InternalError = value.into();
|
477
|
+
err.into()
|
478
|
+
}
|
479
|
+
}
|
480
|
+
};
|
481
|
+
}
|
482
|
+
|
483
|
+
error_as_internal! {ciborium::ser::Error<std::io::Error>}
|
484
|
+
error_as_internal! {ciborium::de::Error<std::io::Error>}
|
485
|
+
error_as_internal! {serde_json::Error}
|
486
|
+
error_as_internal! {std::num::ParseFloatError}
|
487
|
+
|
488
|
+
pub(crate) use error_as_internal;
|
489
|
+
|
490
|
+
#[cfg(feature = "redb")]
|
491
|
+
mod _trait_impl_redb
|
492
|
+
{
|
493
|
+
super::error_as_internal! {redb::Error}
|
494
|
+
macro_rules! redb_error_as_internal {
|
495
|
+
($err_type:ty) => {
|
496
|
+
impl From<$err_type> for crate::prelude::ErrorType
|
497
|
+
{
|
498
|
+
fn from(value: $err_type) -> Self
|
499
|
+
{
|
500
|
+
let redb_err: redb::Error = value.into();
|
501
|
+
let err: crate::error::InternalError = redb_err.into();
|
502
|
+
err.into()
|
503
|
+
}
|
504
|
+
}
|
505
|
+
};
|
506
|
+
}
|
507
|
+
redb_error_as_internal! {redb::StorageError}
|
508
|
+
redb_error_as_internal! {redb::DatabaseError}
|
509
|
+
redb_error_as_internal! {redb::TransactionError}
|
510
|
+
redb_error_as_internal! {redb::TableError}
|
511
|
+
redb_error_as_internal! {redb::CommitError}
|
512
|
+
}
|
513
|
+
#[cfg(feature = "sqlite")]
|
514
|
+
mod _trait_impl_sqlite
|
515
|
+
{
|
516
|
+
error_as_internal! {rusqlite::Error}
|
517
|
+
error_as_internal! {askama::Error}
|
518
|
+
}
|
519
|
+
|
520
|
+
/// Merge a list of error into a string error message
|
521
|
+
pub(crate) fn vec_to_error<E: std::fmt::Display>(errs: &Vec<ErrorType>) -> String
|
522
|
+
{
|
523
|
+
let errs: Vec<String> = errs.iter().map(|x| format!("'{}'", x)).collect();
|
524
|
+
errs.join(", ")
|
525
|
+
}
|
526
|
+
|
527
|
+
pub(crate) fn parse_int_error_to_compile_error<'a>(
|
528
|
+
text: &'a str,
|
529
|
+
e: std::num::ParseIntError,
|
530
|
+
) -> crate::prelude::ErrorType
|
531
|
+
{
|
532
|
+
use std::num::IntErrorKind;
|
533
|
+
match e.kind()
|
534
|
+
{
|
535
|
+
IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => CompileTimeError::IntegerOverflow {
|
536
|
+
text: text.to_owned(),
|
537
|
+
}
|
538
|
+
.into(),
|
539
|
+
_ => InternalError::ParseIntError(e).into(),
|
540
|
+
}
|
541
|
+
}
|
542
|
+
|
543
|
+
/// Convenient macro for mapping errors, for instance, from internal error to runtime error:
|
544
|
+
///
|
545
|
+
/// ```notest
|
546
|
+
/// v.try_into()
|
547
|
+
/// .map_err(|e| error::map_error!(e, Error::Internal(InternalError::InvalidValueCast{..}) => RunTimeError::InvalidArgumentType ))?;
|
548
|
+
/// ```
|
549
|
+
macro_rules! map_error {
|
550
|
+
($err:expr, $source:pat => $destination:expr) => {{
|
551
|
+
use crate::error::*;
|
552
|
+
let (error, meta) = $err.split_error();
|
553
|
+
match error
|
554
|
+
{
|
555
|
+
$source => ErrorType::make_error($destination.into(), meta),
|
556
|
+
o => ErrorType::make_error(o, meta),
|
557
|
+
}
|
558
|
+
}};
|
559
|
+
}
|
560
|
+
|
561
|
+
pub(crate) use map_error;
|
562
|
+
|
563
|
+
use crate::prelude::ErrorType;
|
564
|
+
|
565
|
+
impl From<std::convert::Infallible> for Error
|
566
|
+
{
|
567
|
+
fn from(value: std::convert::Infallible) -> Self
|
568
|
+
{
|
569
|
+
InternalError::Infallible(value).into()
|
570
|
+
}
|
571
|
+
}
|
572
|
+
|
573
|
+
// ____ _ _____
|
574
|
+
// / ___| ___ _ __ ___ _ __(_) ___| ____|_ __ _ __ ___ _ __ ___
|
575
|
+
// | | _ / _ \ '_ \ / _ \ '__| |/ __| _| | '__| '__/ _ \| '__/ __|
|
576
|
+
// | |_| | __/ | | | __/ | | | (__| |___| | | | | (_) | | \__ \
|
577
|
+
// \____|\___|_| |_|\___|_| |_|\___|_____|_| |_| \___/|_| |___/
|
578
|
+
|
579
|
+
pub(crate) trait GenericErrors: Into<Error>
|
580
|
+
{
|
581
|
+
fn unknown_function(name: impl Into<String>) -> Self;
|
582
|
+
fn not_comparable() -> Self;
|
583
|
+
}
|
584
|
+
|
585
|
+
impl GenericErrors for CompileTimeError
|
586
|
+
{
|
587
|
+
fn unknown_function(name: impl Into<String>) -> Self
|
588
|
+
{
|
589
|
+
Self::UnknownFunction { name: name.into() }
|
590
|
+
}
|
591
|
+
fn not_comparable() -> Self
|
592
|
+
{
|
593
|
+
Self::NotComparable
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
impl GenericErrors for RunTimeError
|
598
|
+
{
|
599
|
+
fn unknown_function(name: impl Into<String>) -> Self
|
600
|
+
{
|
601
|
+
Self::UnknownFunction { name: name.into() }
|
602
|
+
}
|
603
|
+
fn not_comparable() -> Self
|
604
|
+
{
|
605
|
+
Self::NotComparable
|
606
|
+
}
|
607
|
+
}
|
608
|
+
|
609
|
+
/// GQLite Result
|
610
|
+
#[cfg(not(feature = "_backtrace"))]
|
611
|
+
pub(crate) mod export
|
612
|
+
{
|
613
|
+
pub type Error = super::Error;
|
614
|
+
}
|
615
|
+
|
616
|
+
/// GQLite Result
|
617
|
+
#[cfg(feature = "_backtrace")]
|
618
|
+
pub(crate) mod export
|
619
|
+
{
|
620
|
+
pub type Error = super::ErrorWithBacktrace;
|
621
|
+
}
|