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
131
132
133
134
135
136
137
138
139
140
141
#[cfg(all(feature = "sea-orm-internal", feature = "sqlx-dep"))]
pub use sqlx::error::Error as SqlxError;
#[cfg(all(feature = "sea-orm-internal", feature = "sqlx-mysql"))]
pub use sqlx::mysql::MySqlDatabaseError as SqlxMySqlError;
#[cfg(all(feature = "sea-orm-internal", feature = "sqlx-postgres"))]
pub use sqlx::postgres::PgDatabaseError as SqlxPostgresError;
#[cfg(all(feature = "sea-orm-internal", feature = "sqlx-sqlite"))]
pub use sqlx::sqlite::SqliteError as SqlxSqliteError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum DbErr {
#[error("Failed to acquire connection from pool")]
ConnectionAcquire,
#[error("Error converting `{from}` into `{into}`: {source}")]
TryIntoErr {
from: &'static str,
into: &'static str,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Connection Error: {0}")]
Conn(#[source] RuntimeErr),
#[error("Execution Error: {0}")]
Exec(#[source] RuntimeErr),
#[error("Query Error: {0}")]
Query(#[source] RuntimeErr),
#[error("Type '{0}' cannot be converted from u64")]
ConvertFromU64(&'static str),
#[error("Failed to unpack last_insert_id")]
UnpackInsertId,
#[error("Failed to get primary key from model")]
UpdateGetPrimaryKey,
#[error("RecordNotFound Error: {0}")]
RecordNotFound(String),
#[error("Attribute {0} is NotSet")]
AttrNotSet(String),
#[error("Custom Error: {0}")]
Custom(String),
#[error("Type Error: {0}")]
Type(String),
#[error("Json Error: {0}")]
Json(String),
#[error("Migration Error: {0}")]
Migration(String),
#[error("None of the records are inserted")]
RecordNotInserted,
#[error("None of the records are updated")]
RecordNotUpdated,
}
#[derive(Error, Debug)]
pub enum RuntimeErr {
#[cfg(feature = "sqlx-dep")]
#[error("{0}")]
SqlxError(sqlx::error::Error),
#[error("{0}")]
Internal(String),
}
impl PartialEq for DbErr {
fn eq(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
}
}
impl Eq for DbErr {}
#[derive(Error, Debug)]
#[error("Failed to match \"{0}\" as Column")]
pub struct ColumnFromStrErr(pub String);
#[allow(dead_code)]
pub(crate) fn conn_err<T>(s: T) -> DbErr
where
T: ToString,
{
DbErr::Conn(RuntimeErr::Internal(s.to_string()))
}
#[allow(dead_code)]
pub(crate) fn exec_err<T>(s: T) -> DbErr
where
T: ToString,
{
DbErr::Exec(RuntimeErr::Internal(s.to_string()))
}
#[allow(dead_code)]
pub(crate) fn query_err<T>(s: T) -> DbErr
where
T: ToString,
{
DbErr::Query(RuntimeErr::Internal(s.to_string()))
}
#[allow(dead_code)]
pub(crate) fn type_err<T>(s: T) -> DbErr
where
T: ToString,
{
DbErr::Type(s.to_string())
}
#[allow(dead_code)]
pub(crate) fn json_err<T>(s: T) -> DbErr
where
T: ToString,
{
DbErr::Json(s.to_string())
}