#[non_exhaustive]pub enum Error {
NotFound {
table: &'static str,
key: Option<String>,
},
Conflict {
table: &'static str,
key: String,
},
Validation(ValidationErrors),
Hook(Box<dyn Error + Sync + Send>),
InvalidCursor(String),
Encode(Box<dyn Error + Sync + Send>),
Config(String),
InvalidQuery(String),
Database(Error),
Migrate(MigrateError),
}Expand description
Every error rok-db can produce.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NotFound
A query that must return a row returned nothing.
Fields
Conflict
An optimistic-locking check failed: the record was changed by someone
else since it was loaded (its #[rok(version)] column no longer
matches). Reload the record and retry.
Validation(ValidationErrors)
The record failed validation (#[rok(validate(…))]); nothing was
written.
Hook(Box<dyn Error + Sync + Send>)
A lifecycle hook rejected the operation or failed.
InvalidCursor(String)
A pagination cursor could not be decoded.
Encode(Box<dyn Error + Sync + Send>)
Binding a parameter to the query failed.
Config(String)
The configuration (e.g. DATABASE_URL) is missing or invalid.
InvalidQuery(String)
A query was built in a way that cannot be executed.
Database(Error)
An error reported by the database driver.
Migrate(MigrateError)
An error raised while running migrations.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
true if this is a Error::NotFound (or the driver’s own RowNotFound).
Sourcepub fn hook(error: impl Into<Box<dyn Error + Sync + Send>>) -> Error
pub fn hook(error: impl Into<Box<dyn Error + Sync + Send>>) -> Error
Wrap any error returned from a Hooks method.
Sourcepub fn validation_errors(&self) -> Option<&ValidationErrors>
pub fn validation_errors(&self) -> Option<&ValidationErrors>
The validation errors, if this is an Error::Validation.
Sourcepub fn is_conflict(&self) -> bool
pub fn is_conflict(&self) -> bool
true if this is an optimistic-locking Error::Conflict.
Sourcepub fn is_serialization_failure(&self) -> bool
pub fn is_serialization_failure(&self) -> bool
true for a serialization failure or deadlock (SQLSTATE 40001 /
40P01): the transaction can be retried as a whole.
Sourcepub fn is_unique_violation(&self) -> bool
pub fn is_unique_violation(&self) -> bool
true if the database rejected the query because of a unique constraint.
Sourcepub fn is_foreign_key_violation(&self) -> bool
pub fn is_foreign_key_violation(&self) -> bool
true if the database rejected the query because of a foreign key constraint.
Sourcepub fn constraint(&self) -> Option<&str>
pub fn constraint(&self) -> Option<&str>
The name of the violated constraint, if any.
Source§impl Error
impl Error
Sourcepub fn http_status(&self) -> (StatusCode, &'static str)
pub fn http_status(&self) -> (StatusCode, &'static str)
The HTTP status and machine-readable code this error maps to.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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<MigrateError> for Error
impl From<MigrateError> for Error
Source§fn from(source: MigrateError) -> Error
fn from(source: MigrateError) -> Error
Source§impl IntoResponse for Error
impl IntoResponse for Error
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<M> InScope<(M, ()), Here> for M
impl<M, Rest, N> InScope<(M, (Rest, N)), Last> for N
impl<X, M, Rest, N, I> InScope<(M, (Rest, N)), There<I>> for X
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