#[cfg(feature = "sqlx-dep")]
use sqlx::error::Error as SqlxError;
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),
}
#[derive(Error, Debug)]
pub enum RuntimeErr {
#[cfg(feature = "sqlx-dep")]
#[error("{0}")]
SqlxError(SqlxError),
#[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);