pub struct DatabaseError {
pub code: ErrorCode,
pub sql_state: String,
pub severity: String,
pub message: String,
pub details: Box<ErrorDetails>,
}Expand description
An error a database reported, or a failure to reach it.
A failure to reach the database, which the server can’t report, has
DatabaseError::CONNECTION_FAILURE_SQLSTATE,
ErrorCode::ConnectionFailure, the client’s message and none of the
optional fields.
The optional fields, in ErrorDetails, are sent only for some errors
(see https://www.postgresql.org/docs/current/protocol-error-fields.html);
one being there says nothing about the others.
Fields§
§code: ErrorCodeWhat kind of error it is, by its SQLSTATE.
sql_state: StringThe SQLSTATE: "23505".
severity: StringERROR, FATAL or PANIC.
message: StringThe primary message: accurate, terse, one line.
details: Box<ErrorDetails>The optional fields, boxed so the error stays small: a Result with
it costs little where nothing fails. DatabaseError::detail and the
other accessors read them.
Implementations§
Source§impl DatabaseError
impl DatabaseError
Sourcepub const CONNECTION_FAILURE_SQLSTATE: &'static str = "08001"
pub const CONNECTION_FAILURE_SQLSTATE: &'static str = "08001"
The SQLSTATE of a database that couldn’t be reached:
sqlclient_unable_to_establish_sqlconnection.
Sourcepub fn from_db_error(err: &DbError) -> DatabaseError
pub fn from_db_error(err: &DbError) -> DatabaseError
The error the server reported in err.
Sourcepub fn connection_failure(message: impl Into<String>) -> DatabaseError
pub fn connection_failure(message: impl Into<String>) -> DatabaseError
A failure to reach the database, or to stay connected to it, which
message describes.
Sourcepub fn from_client_error(err: &Error) -> Option<DatabaseError>
pub fn from_client_error(err: &Error) -> Option<DatabaseError>
The error in err, if it is one the server reported or a failure to
reach it; None for the caller’s mistakes, such as a parameter of the
wrong type.
Sourcepub fn detail(&self) -> Option<&str>
pub fn detail(&self) -> Option<&str>
A secondary message with more detail, such as the key a unique violation conflicted on.
Sourcepub fn schema_name(&self) -> Option<&str>
pub fn schema_name(&self) -> Option<&str>
The schema of the object the error is about.
Sourcepub fn table_name(&self) -> Option<&str>
pub fn table_name(&self) -> Option<&str>
The table the error is about.
Sourcepub fn column_name(&self) -> Option<&str>
pub fn column_name(&self) -> Option<&str>
The column the error is about.
Sourcepub fn data_type_name(&self) -> Option<&str>
pub fn data_type_name(&self) -> Option<&str>
The data type the error is about.
Sourcepub fn constraint_name(&self) -> Option<&str>
pub fn constraint_name(&self) -> Option<&str>
The constraint the error is about; an index counts as one.
Trait Implementations§
Source§impl Clone for DatabaseError
impl Clone for DatabaseError
Source§fn clone(&self) -> DatabaseError
fn clone(&self) -> DatabaseError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DatabaseError
impl Debug for DatabaseError
Source§impl Display for DatabaseError
ERROR: duplicate key value violates unique constraint "users_pkey" (Code unique_violation: SQLSTATE 23505), as Go’s postgres.Error reads.
impl Display for DatabaseError
ERROR: duplicate key value violates unique constraint "users_pkey" (Code unique_violation: SQLSTATE 23505), as Go’s postgres.Error reads.
impl Eq for DatabaseError
Source§impl Error for DatabaseError
impl Error for DatabaseError
1.30.0 · 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<DatabaseError> for Error
impl From<DatabaseError> for Error
Source§fn from(source: DatabaseError) -> Self
fn from(source: DatabaseError) -> Self
Source§impl PartialEq for DatabaseError
impl PartialEq for DatabaseError
impl StructuralPartialEq for DatabaseError
Auto Trait Implementations§
impl Forget for DatabaseError
impl Freeze for DatabaseError
impl Move for DatabaseError
impl RefUnwindSafe for DatabaseError
impl Send for DatabaseError
impl Sync for DatabaseError
impl Unpin for DatabaseError
impl UnsafeUnpin for DatabaseError
impl UnwindSafe for DatabaseError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request