#[non_exhaustive]pub enum DbErr {
Show 22 variants
ConnectionAcquire(ConnAcquireErr),
TryIntoErr {
from: &'static str,
into: &'static str,
source: Arc<dyn Error + Sync + Send>,
},
Conn(RuntimeErr),
Exec(RuntimeErr),
Query(RuntimeErr),
ConvertFromU64(&'static str),
UnpackInsertId,
UpdateGetPrimaryKey,
RecordNotFound(String),
AttrNotSet(String),
Custom(String),
Type(String),
Json(String),
Migration(String),
RecordNotInserted,
RecordNotUpdated,
BackendNotSupported {
db: &'static str,
ctx: &'static str,
},
KeyArityMismatch {
expected: u8,
received: u8,
},
PrimaryKeyNotSet {
ctx: &'static str,
},
RbacError(String),
AccessDenied {
permission: String,
resource: String,
},
MutexPoisonError,
}Expand description
An error from unsuccessful database operations
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ConnectionAcquire(ConnAcquireErr)
This error can happen when the connection pool is fully-utilized
TryIntoErr
Runtime type conversion error
Fields
Conn(RuntimeErr)
There was a problem with the database connection
Exec(RuntimeErr)
An operation did not execute successfully
Query(RuntimeErr)
An error occurred while performing a query
ConvertFromU64(&'static str)
Type error: the specified type cannot be converted from u64. This is not a runtime error.
UnpackInsertId
After an insert statement it was impossible to retrieve the last_insert_id
UpdateGetPrimaryKey
When updating, a model should know its primary key to check if the record has been correctly updated, otherwise this error will occur
RecordNotFound(String)
The record was not found in the database
AttrNotSet(String)
Thrown by TryFrom<ActiveModel>, which assumes all attributes are set/unchanged
Custom(String)
A custom error
Type(String)
Error occurred while parsing value as target type
Json(String)
Error occurred while parsing json value as target type
Migration(String)
A migration error
RecordNotInserted
None of the records are inserted, that probably means all of them conflict with existing records in the table
RecordNotUpdated
None of the records are updated, that means a WHERE condition has no matches. May be the table is empty or the record does not exist
BackendNotSupported
This operation is not supported by the database backend
KeyArityMismatch
(Primary) Key arity mismatch
PrimaryKeyNotSet
Primay key not set for update / delete
RbacError(String)
Error while running RBAC checks
AccessDenied
Access denied after running RBAC checks
MutexPoisonError
Mutex was poisoned by another thread
Implementations§
Source§impl DbErr
impl DbErr
Sourcepub fn sql_err(&self) -> Option<SqlErr>
pub fn sql_err(&self) -> Option<SqlErr>
Classify this error as a portable SqlErr — a unique-key or
foreign-key constraint violation — returning None if it is neither, or
if it did not originate from a database driver.
Only the two most common constraint violations are recognized, across
MySQL, Postgres and SQLite. For anything else (SQLSTATE codes, check
constraints, other driver-specific detail) match on the underlying
RuntimeErr::SqlxError and inspect the driver error yourself:
use sea_orm::{DbErr, RuntimeErr};
use std::ops::Deref;
if let Some(sql_err) = err.sql_err() {
// Portable across MySQL / Postgres / SQLite.
eprintln!("constraint violation: {sql_err}");
} else if let DbErr::Query(RuntimeErr::SqlxError(e)) | DbErr::Exec(RuntimeErr::SqlxError(e)) =
&err
&& let sea_orm::sqlx::Error::Database(db_err) = e.deref()
{
// Backend-specific: inspect the raw driver error.
eprintln!("SQLSTATE: {:?}", db_err.code());
}Trait Implementations§
impl Eq for DbErr
Source§impl Error for DbErr
impl Error for DbErr
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<TryGetError> for DbErr
impl From<TryGetError> for DbErr
Source§fn from(e: TryGetError) -> DbErr
fn from(e: TryGetError) -> DbErr
Auto Trait Implementations§
impl !RefUnwindSafe for DbErr
impl !UnwindSafe for DbErr
impl Freeze for DbErr
impl Send for DbErr
impl Sync for DbErr
impl Unpin for DbErr
impl UnsafeUnpin for DbErr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more