#[non_exhaustive]pub enum DbError {
ConnectionFailed {
url: String,
message: String,
},
QueryFailed {
table: &'static str,
operation: &'static str,
message: String,
},
ConstraintViolation {
table: &'static str,
constraint: String,
message: String,
},
MigrationFailed {
version: i32,
message: String,
},
TransactionFailed {
message: String,
},
PoolExhausted {
timeout_ms: u64,
},
SerializationError {
field: String,
message: String,
},
Other(String),
}Expand description
Specific database error types with context.
This enum provides detailed, typed database errors that preserve context
about what operation failed and why. Use CommerceError::as_db_error()
to extract the underlying database error for detailed handling.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
ConnectionFailed
Failed to establish database connection.
QueryFailed
Query execution failed.
Fields
ConstraintViolation
Constraint violation (unique, foreign key, check).
Fields
MigrationFailed
Database migration failed.
TransactionFailed
Transaction error.
PoolExhausted
Connection pool exhausted.
SerializationError
Serialization/deserialization error.
Fields
Other(String)
Generic database error (fallback).
Implementations§
Source§impl DbError
impl DbError
Sourcepub fn query_failed(
table: &'static str,
operation: &'static str,
message: impl Into<String>,
) -> Self
pub fn query_failed( table: &'static str, operation: &'static str, message: impl Into<String>, ) -> Self
Create a query failed error.
Sourcepub fn constraint_violation(
table: &'static str,
constraint: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn constraint_violation( table: &'static str, constraint: impl Into<String>, message: impl Into<String>, ) -> Self
Create a constraint violation error.
Sourcepub fn connection_failed(
url: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn connection_failed( url: impl Into<String>, message: impl Into<String>, ) -> Self
Create a connection failed error.
Sourcepub fn transaction_failed(message: impl Into<String>) -> Self
pub fn transaction_failed(message: impl Into<String>) -> Self
Create a transaction failed error.
Trait Implementations§
Source§impl Error for DbError
impl Error for DbError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for DbError
impl RefUnwindSafe for DbError
impl Send for DbError
impl Sync for DbError
impl Unpin for DbError
impl UnsafeUnpin for DbError
impl UnwindSafe for DbError
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
Mutably borrows from an owned value. Read more