1use std::{error, fmt};
4
5use sqlx::Error as SqlxError;
6
7use crate::row::OwnedRowError;
8
9#[derive(Debug)]
11pub enum Error {
12 SqlxError(SqlxError),
14
15 ConfigurationError(String),
17
18 SQLBuildError(rorm_sql::error::Error),
20
21 RowError(OwnedRowError),
23}
24
25impl error::Error for Error {
26 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
27 match self {
28 Error::SqlxError(source) => Some(source),
29 Error::ConfigurationError(_) => None,
30 Error::SQLBuildError(source) => Some(source),
31 Error::RowError(source) => Some(source),
32 }
33 }
34}
35
36impl fmt::Display for Error {
37 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38 match self {
39 Error::SqlxError(error) => write!(f, "sqlx error: {error}"),
40 Error::ConfigurationError(error) => write!(f, "configuration error: {error}",),
41 Error::SQLBuildError(error) => {
42 write!(f, "sql error: {error}")
43 }
44 Error::RowError(error) => {
45 write!(f, "{error}")
46 }
47 }
48 }
49}
50
51impl From<SqlxError> for Error {
52 fn from(source: SqlxError) -> Self {
53 Error::SqlxError(source)
54 }
55}
56
57impl From<rorm_sql::error::Error> for Error {
58 fn from(source: rorm_sql::error::Error) -> Self {
59 Error::SQLBuildError(source)
60 }
61}