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
use crate::sql_builder::sql_builder_error::SqlBuilderError;
use crate::{
deserialize::error::DeserializeError, sql_arg::error::TryFromSqlArgError,
sql_expr::resolver_error::ResolverError, table_mapper::error::TableMapperError,
};
use pest::error::Error as PestError;
use thiserror::Error;
#[macro_export]
macro_rules! ok_or_fail {
( $var:expr ) => {
$var.as_ref().ok_or(toql::error::ToqlError::ValueMissing(
stringify!($var).to_string(),
))
};
}
#[derive(Error, Debug)]
pub enum ToqlError {
#[error("no result found")]
NotFound,
#[error("no unique result found")]
NotUnique,
#[error("no joined value found, but expected one")]
JoinExpected,
#[error("{0}")]
QueryParserError(#[from] PestError<toql_query_parser::Rule>),
#[error("{0}")]
SqlExprParserError(#[from] PestError<toql_sql_expr_parser::Rule>),
#[error("{0}")]
RoleExprParserError(#[from] PestError<toql_role_expr_parser::Rule>),
#[error("{0}")]
EncodingError(#[from] std::str::Utf8Error),
#[error("no mapper found for `{0}`")]
MapperMissing(String),
#[error("{0}")]
TryFromSqlArgError(#[from] TryFromSqlArgError),
#[error("{0}")]
TableMapperError(#[from] TableMapperError),
#[error("no value found for `{0}`")]
ValueMissing(String),
#[error("{0}")]
SqlBuilderError(#[from] SqlBuilderError),
#[error("{0}")]
DeserializeError(#[from] DeserializeError),
#[error("{0}")]
SqlExprResolverError(#[from] ResolverError),
#[error("failed to access registry: `{0}`")]
RegistryPoisenError(String),
#[error("{0}")]
NoneError(String),
}
impl<PE> From<std::sync::PoisonError<PE>> for ToqlError {
fn from(err: std::sync::PoisonError<PE>) -> ToqlError {
ToqlError::RegistryPoisenError(err.to_string())
}
}