gqlite 1.2.0 → 1.2.3

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gqliterb/.cargo/config.toml +2 -0
  3. data/ext/gqliterb/Cargo.lock +152 -135
  4. data/ext/gqliterb/Cargo.toml +4 -6
  5. data/ext/gqliterb/src/lib.rs +8 -2
  6. data/ext/gqliterb/vendor/gqlitedb/Cargo.lock +2115 -0
  7. data/ext/gqliterb/vendor/gqlitedb/Cargo.toml +138 -0
  8. data/ext/gqliterb/vendor/gqlitedb/askama.toml +3 -0
  9. data/ext/gqliterb/vendor/gqlitedb/benches/common/mod.rs +25 -0
  10. data/ext/gqliterb/vendor/gqlitedb/benches/common/pokec.rs +185 -0
  11. data/ext/gqliterb/vendor/gqlitedb/benches/pokec_divan.rs +137 -0
  12. data/ext/gqliterb/vendor/gqlitedb/benches/pokec_iai.rs +122 -0
  13. data/ext/gqliterb/vendor/gqlitedb/release.toml +7 -0
  14. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/arithmetic.rs +96 -0
  15. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/containers.rs +33 -0
  16. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/count.rs +35 -0
  17. data/ext/gqliterb/vendor/gqlitedb/src/aggregators/stats.rs +168 -0
  18. data/ext/gqliterb/vendor/gqlitedb/src/aggregators.rs +74 -0
  19. data/ext/gqliterb/vendor/gqlitedb/src/capi.rs +259 -0
  20. data/ext/gqliterb/vendor/gqlitedb/src/compiler/expression_analyser.rs +431 -0
  21. data/ext/gqliterb/vendor/gqlitedb/src/compiler/variables_manager.rs +621 -0
  22. data/ext/gqliterb/vendor/gqlitedb/src/compiler.rs +1115 -0
  23. data/ext/gqliterb/vendor/gqlitedb/src/connection.rs +342 -0
  24. data/ext/gqliterb/vendor/gqlitedb/src/consts.rs +10 -0
  25. data/ext/gqliterb/vendor/gqlitedb/src/error.rs +613 -0
  26. data/ext/gqliterb/vendor/gqlitedb/src/functions/containers.rs +115 -0
  27. data/ext/gqliterb/vendor/gqlitedb/src/functions/edge.rs +20 -0
  28. data/ext/gqliterb/vendor/gqlitedb/src/functions/math.rs +44 -0
  29. data/ext/gqliterb/vendor/gqlitedb/src/functions/node.rs +16 -0
  30. data/ext/gqliterb/vendor/gqlitedb/src/functions/path.rs +80 -0
  31. data/ext/gqliterb/vendor/gqlitedb/src/functions/scalar.rs +86 -0
  32. data/ext/gqliterb/vendor/gqlitedb/src/functions/string.rs +28 -0
  33. data/ext/gqliterb/vendor/gqlitedb/src/functions/value.rs +99 -0
  34. data/ext/gqliterb/vendor/gqlitedb/src/functions.rs +410 -0
  35. data/ext/gqliterb/vendor/gqlitedb/src/graph.rs +283 -0
  36. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/evaluators.rs +1776 -0
  37. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/instructions.rs +267 -0
  38. data/ext/gqliterb/vendor/gqlitedb/src/interpreter/mod.rs +4 -0
  39. data/ext/gqliterb/vendor/gqlitedb/src/lib.rs +41 -0
  40. data/ext/gqliterb/vendor/gqlitedb/src/parser/ast.rs +611 -0
  41. data/ext/gqliterb/vendor/gqlitedb/src/parser/gql.pest +196 -0
  42. data/ext/gqliterb/vendor/gqlitedb/src/parser/parser.rs +1183 -0
  43. data/ext/gqliterb/vendor/gqlitedb/src/parser.rs +4 -0
  44. data/ext/gqliterb/vendor/gqlitedb/src/prelude.rs +8 -0
  45. data/ext/gqliterb/vendor/gqlitedb/src/serialize_with.rs +94 -0
  46. data/ext/gqliterb/vendor/gqlitedb/src/store/pgql.rs +121 -0
  47. data/ext/gqliterb/vendor/gqlitedb/src/store/redb.rs +1262 -0
  48. data/ext/gqliterb/vendor/gqlitedb/src/store/sqlite.rs +1026 -0
  49. data/ext/gqliterb/vendor/gqlitedb/src/store.rs +439 -0
  50. data/ext/gqliterb/vendor/gqlitedb/src/tests/compiler.rs +92 -0
  51. data/ext/gqliterb/vendor/gqlitedb/src/tests/evaluators.rs +227 -0
  52. data/ext/gqliterb/vendor/gqlitedb/src/tests/parser.rs +81 -0
  53. data/ext/gqliterb/vendor/gqlitedb/src/tests/store/redb.rs +46 -0
  54. data/ext/gqliterb/vendor/gqlitedb/src/tests/store/sqlite.rs +46 -0
  55. data/ext/gqliterb/vendor/gqlitedb/src/tests/store.rs +470 -0
  56. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/ast.rs +356 -0
  57. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates/programs.rs +455 -0
  58. data/ext/gqliterb/vendor/gqlitedb/src/tests/templates.rs +2 -0
  59. data/ext/gqliterb/vendor/gqlitedb/src/tests.rs +39 -0
  60. data/ext/gqliterb/vendor/gqlitedb/src/utils.rs +28 -0
  61. data/ext/gqliterb/vendor/gqlitedb/src/value/compare.rs +212 -0
  62. data/ext/gqliterb/vendor/gqlitedb/src/value/contains.rs +47 -0
  63. data/ext/gqliterb/vendor/gqlitedb/src/value/value_map.rs +298 -0
  64. data/ext/gqliterb/vendor/gqlitedb/src/value.rs +609 -0
  65. data/ext/gqliterb/vendor/gqlitedb/src/value_table.rs +610 -0
  66. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/call_stats.sql +22 -0
  67. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_count_for_node.sql +3 -0
  68. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_create.sql +6 -0
  69. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete.sql +1 -0
  70. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_delete_by_nodes.sql +2 -0
  71. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_select.sql +139 -0
  72. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/edge_update.sql +4 -0
  73. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_create.sql +16 -0
  74. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/graph_delete.sql +3 -0
  75. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_create_table.sql +1 -0
  76. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_get.sql +1 -0
  77. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/metadata_set.sql +1 -0
  78. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_create.sql +1 -0
  79. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_delete.sql +1 -0
  80. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_select.sql +42 -0
  81. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/node_update.sql +4 -0
  82. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/table_exists.sql +5 -0
  83. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_from_1_01.sql +2 -0
  84. data/ext/gqliterb/vendor/gqlitedb/templates/sql/sqlite/upgrade_graph_from_1_01.sql +65 -0
  85. metadata +82 -2
@@ -0,0 +1,613 @@
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
+ ccutils::assert_impl_all!(Error: Send, Sync);
376
+
377
+ impl Error
378
+ {
379
+ /// Return the underlying error (match WithBacktrace API)
380
+ pub fn error(&self) -> &Error
381
+ {
382
+ self
383
+ }
384
+ pub(crate) fn split_error(self) -> (Error, ())
385
+ {
386
+ (self, ())
387
+ }
388
+ pub(crate) fn make_error(error: Error, _: ()) -> Error
389
+ {
390
+ error
391
+ }
392
+ }
393
+
394
+ // _____ __ ___ _ _ ____ _ _
395
+ // | ____|_ __ _ __ ___ _ _\ \ / (_) |_| |__ | __ ) __ _ ___| | __ |_ _ __ __ _ ___ ___
396
+ // | _| | '__| '__/ _ \| '__\ \ /\ / /| | __| '_ \| _ \ / _` |/ __| |/ / __| '__/ _` |/ __/ _ \
397
+ // | |___| | | | | (_) | | \ V V / | | |_| | | | |_) | (_| | (__| <| |_| | | (_| | (_| __/
398
+ // |_____|_| |_| \___/|_| \_/\_/ |_|\__|_| |_|____/ \__,_|\___|_|\_\\__|_| \__,_|\___\___|
399
+
400
+ #[derive(Debug)]
401
+ #[cfg(feature = "_backtrace")]
402
+ pub struct ErrorWithBacktrace
403
+ {
404
+ error: Error,
405
+ backtrace: std::backtrace::Backtrace,
406
+ }
407
+
408
+ #[cfg(feature = "_backtrace")]
409
+ impl ErrorWithBacktrace
410
+ {
411
+ /// Return the underlying error
412
+ pub fn error(&self) -> &Error
413
+ {
414
+ &self.error
415
+ }
416
+ pub(crate) fn split_error(self) -> (Error, std::backtrace::Backtrace)
417
+ {
418
+ (self.error, self.backtrace)
419
+ }
420
+ pub(crate) fn make_error(error: Error, backtrace: std::backtrace::Backtrace) -> Self
421
+ {
422
+ Self { error, backtrace }
423
+ }
424
+ }
425
+
426
+ #[cfg(feature = "_backtrace")]
427
+ impl std::fmt::Display for ErrorWithBacktrace
428
+ {
429
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
430
+ {
431
+ self.error.fmt(f)
432
+ }
433
+ }
434
+
435
+ #[cfg(feature = "_backtrace")]
436
+ impl<T> From<T> for ErrorWithBacktrace
437
+ where
438
+ T: Into<Error>,
439
+ {
440
+ fn from(value: T) -> Self
441
+ {
442
+ Self {
443
+ error: value.into(),
444
+ backtrace: std::backtrace::Backtrace::capture(),
445
+ }
446
+ }
447
+ }
448
+
449
+ // ____ _
450
+ // / ___|___ _ ____ _____ _ __ ___(_) ___ _ __
451
+ // | | / _ \| '_ \ \ / / _ \ '__/ __| |/ _ \| '_ \
452
+ // | |__| (_) | | | \ V / __/ | \__ \ | (_) | | | |
453
+ // \____\___/|_| |_|\_/ \___|_| |___/_|\___/|_| |_|
454
+
455
+ impl<T> From<std::sync::PoisonError<T>> for Error
456
+ {
457
+ fn from(value: std::sync::PoisonError<T>) -> Self
458
+ {
459
+ InternalError::Poison(format!("{:?}", value)).into()
460
+ }
461
+ }
462
+
463
+ impl From<pest::error::Error<crate::parser::parser::Rule>> for Error
464
+ {
465
+ fn from(value: pest::error::Error<crate::parser::parser::Rule>) -> Self
466
+ {
467
+ CompileTimeError::from(value).into()
468
+ }
469
+ }
470
+
471
+ macro_rules! error_as_internal {
472
+ ($err_type:ty) => {
473
+ impl From<$err_type> for crate::prelude::ErrorType
474
+ {
475
+ fn from(value: $err_type) -> Self
476
+ {
477
+ let err: crate::error::InternalError = value.into();
478
+ err.into()
479
+ }
480
+ }
481
+ };
482
+ }
483
+
484
+ error_as_internal! {ciborium::ser::Error<std::io::Error>}
485
+ error_as_internal! {ciborium::de::Error<std::io::Error>}
486
+ error_as_internal! {serde_json::Error}
487
+ error_as_internal! {std::num::ParseFloatError}
488
+
489
+ pub(crate) use error_as_internal;
490
+
491
+ #[cfg(feature = "redb")]
492
+ mod _trait_impl_redb
493
+ {
494
+ super::error_as_internal! {redb::Error}
495
+ macro_rules! redb_error_as_internal {
496
+ ($err_type:ty) => {
497
+ impl From<$err_type> for crate::prelude::ErrorType
498
+ {
499
+ fn from(value: $err_type) -> Self
500
+ {
501
+ let redb_err: redb::Error = value.into();
502
+ let err: crate::error::InternalError = redb_err.into();
503
+ err.into()
504
+ }
505
+ }
506
+ };
507
+ }
508
+ redb_error_as_internal! {redb::StorageError}
509
+ redb_error_as_internal! {redb::DatabaseError}
510
+ redb_error_as_internal! {redb::TransactionError}
511
+ redb_error_as_internal! {redb::TableError}
512
+ redb_error_as_internal! {redb::CommitError}
513
+ }
514
+ #[cfg(feature = "sqlite")]
515
+ mod _trait_impl_sqlite
516
+ {
517
+ error_as_internal! {rusqlite::Error}
518
+ error_as_internal! {askama::Error}
519
+ }
520
+
521
+ /// Merge a list of error into a string error message
522
+ pub(crate) fn vec_to_error<E: std::fmt::Display>(errs: &Vec<ErrorType>) -> String
523
+ {
524
+ let errs: Vec<String> = errs.iter().map(|x| format!("'{}'", x)).collect();
525
+ errs.join(", ")
526
+ }
527
+
528
+ pub(crate) fn parse_int_error_to_compile_error<'a>(
529
+ text: &'a str,
530
+ e: std::num::ParseIntError,
531
+ ) -> crate::prelude::ErrorType
532
+ {
533
+ use std::num::IntErrorKind;
534
+ match e.kind()
535
+ {
536
+ IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => CompileTimeError::IntegerOverflow {
537
+ text: text.to_owned(),
538
+ }
539
+ .into(),
540
+ _ => InternalError::ParseIntError(e).into(),
541
+ }
542
+ }
543
+
544
+ /// Convenient macro for mapping errors, for instance, from internal error to runtime error:
545
+ ///
546
+ /// ```notest
547
+ /// v.try_into()
548
+ /// .map_err(|e| error::map_error!(e, Error::Internal(InternalError::InvalidValueCast{..}) => RunTimeError::InvalidArgumentType ))?;
549
+ /// ```
550
+ macro_rules! map_error {
551
+ ($err:expr, $source:pat => $destination:expr) => {{
552
+ use crate::error::*;
553
+ let (error, meta) = $err.split_error();
554
+ match error
555
+ {
556
+ $source => ErrorType::make_error($destination.into(), meta),
557
+ o => ErrorType::make_error(o, meta),
558
+ }
559
+ }};
560
+ }
561
+
562
+ pub(crate) use map_error;
563
+
564
+ use crate::prelude::ErrorType;
565
+
566
+ impl From<std::convert::Infallible> for Error
567
+ {
568
+ fn from(value: std::convert::Infallible) -> Self
569
+ {
570
+ InternalError::Infallible(value).into()
571
+ }
572
+ }
573
+
574
+ // ____ _ _____
575
+ // / ___| ___ _ __ ___ _ __(_) ___| ____|_ __ _ __ ___ _ __ ___
576
+ // | | _ / _ \ '_ \ / _ \ '__| |/ __| _| | '__| '__/ _ \| '__/ __|
577
+ // | |_| | __/ | | | __/ | | | (__| |___| | | | | (_) | | \__ \
578
+ // \____|\___|_| |_|\___|_| |_|\___|_____|_| |_| \___/|_| |___/
579
+
580
+ pub(crate) trait GenericErrors: Into<Error>
581
+ {
582
+ fn unknown_function(name: impl Into<String>) -> 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
+ }
592
+
593
+ impl GenericErrors for RunTimeError
594
+ {
595
+ fn unknown_function(name: impl Into<String>) -> Self
596
+ {
597
+ Self::UnknownFunction { name: name.into() }
598
+ }
599
+ }
600
+
601
+ /// GQLite Result
602
+ #[cfg(not(feature = "_backtrace"))]
603
+ pub(crate) mod export
604
+ {
605
+ pub type Error = super::Error;
606
+ }
607
+
608
+ /// GQLite Result
609
+ #[cfg(feature = "_backtrace")]
610
+ pub(crate) mod export
611
+ {
612
+ pub type Error = super::ErrorWithBacktrace;
613
+ }