-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherror.rs
130 lines (125 loc) · 4.69 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Errors for translation.
use query_engine_metadata::metadata::database;
/// A type for translation errors.
#[derive(Debug, Clone)]
pub enum Error {
CollectionNotFound(String),
ProcedureNotFound(String),
ColumnNotFoundInCollection(String, String),
RelationshipNotFound(String),
ArgumentNotFound(String),
OperatorNotFound {
operator_name: String,
type_name: database::ScalarType,
},
NonScalarTypeUsedInOperator {
r#type: database::Type,
},
RelationshipArgumentWasOverriden(String),
EmptyPathForOrderByAggregate,
MissingAggregateForArrayRelationOrdering,
TypeMismatch(serde_json::Value, database::ScalarType),
UnexpectedVariable,
CapabilityNotSupported(UnsupportedCapabilities),
UnableToDeserializeNumberAsF64(serde_json::Number),
ColumnIsGenerated(String),
ColumnIsIdentityAlways(String),
MissingColumnInInsert(String, String),
NotImplementedYet(String),
InternalError(String),
}
/// Capabilities we don't currently support.
#[derive(Debug, Clone)]
pub enum UnsupportedCapabilities {}
impl std::fmt::Display for UnsupportedCapabilities {
fn fmt(&self, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
todo!()
}
}
/// Display errors.
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::CollectionNotFound(collection_name) => {
write!(f, "Collection '{}' not found.", collection_name)
}
Error::ProcedureNotFound(procedure_name) => {
write!(f, "Procedure '{}' not found.", procedure_name)
}
Error::ColumnNotFoundInCollection(column_name, collection_name) => write!(
f,
"Column '{}' not found in collection '{}'.",
column_name, collection_name
),
Error::RelationshipNotFound(relationship_name) => {
write!(f, "Relationship '{}' not found.", relationship_name)
}
Error::ArgumentNotFound(argument) => {
write!(f, "Argument '{}' not found.", argument)
}
Error::OperatorNotFound {
operator_name,
type_name,
} => {
write!(
f,
"Operator '{}' not found in type {:?}.",
operator_name, type_name
)
}
Error::RelationshipArgumentWasOverriden(key) => {
write!(f, "The relationship argument '{}' was defined as part of the relationship, but was overriden.", key)
}
Error::EmptyPathForOrderByAggregate => {
write!(f, "No path elements supplied for order by aggregate.")
}
Error::MissingAggregateForArrayRelationOrdering => {
write!(
f,
"No aggregation function was suppilied for ordering on an array relationship."
)
}
Error::TypeMismatch(value, typ) => {
write!(f, "Value '{:?}' is not of type '{:?}'.", value, typ)
}
Error::UnexpectedVariable => {
write!(
f,
"Unexpected variable in a query request which does not contain variables."
)
}
Error::UnableToDeserializeNumberAsF64(num) => {
write!(f, "Unable to deserialize the number '{}' as f64.", num)
}
Error::ColumnIsGenerated(column) => {
write!(
f,
"Unable to insert into the generated column '{}'.",
column
)
}
Error::ColumnIsIdentityAlways(column) => {
write!(f, "Unable to insert into the identity column '{}'.", column)
}
Error::MissingColumnInInsert(column, collection) => {
write!(
f,
"Unable to insert into '{}'. Column '{}' is missing.",
collection, column
)
}
Error::CapabilityNotSupported(thing) => {
write!(f, "Queries containing {} are not supported.", thing)
}
Error::NotImplementedYet(thing) => {
write!(f, "Queries containing {} are not supported.", thing)
}
Error::InternalError(thing) => {
write!(f, "Internal error: {}.", thing)
}
Error::NonScalarTypeUsedInOperator { r#type } => {
write!(f, "Non-scalar-type used in operator: {:?}", r#type)
}
}
}
}