Skip to main content

DatabaseError

Trait DatabaseError 

Source
pub trait DatabaseError:
    'static
    + Send
    + Sync
    + Error {
    // Required methods
    fn message(&self) -> &str;
    fn kind(&self) -> ErrorKind;

    // Provided methods
    fn code(&self) -> Option<Cow<'_, str>> { ... }
    fn constraint(&self) -> Option<&str> { ... }
    fn table(&self) -> Option<&str> { ... }
    fn is_unique_violation(&self) -> bool { ... }
    fn is_foreign_key_violation(&self) -> bool { ... }
    fn is_check_violation(&self) -> bool { ... }
}
Expand description

An error that was returned from the database.

Required Methods§

Source

fn message(&self) -> &str

The primary, human-readable error message.

Source

fn kind(&self) -> ErrorKind

Returns the kind of the error, if supported.

§Note

Not all back-ends behave the same when reporting the error code.

Provided Methods§

Source

fn code(&self) -> Option<Cow<'_, str>>

The (SQLSTATE) code for the error.

Source

fn constraint(&self) -> Option<&str>

Returns the name of the constraint that triggered the error, if applicable. If the error was caused by a conflict of a unique index, this will be the index name.

§Note

Currently only populated by the Postgres driver.

Source

fn table(&self) -> Option<&str>

Returns the name of the table that was affected by the error, if applicable.

§Note

Currently only populated by the Postgres driver.

Source

fn is_unique_violation(&self) -> bool

Returns whether the error kind is a violation of a unique/primary key constraint.

Source

fn is_foreign_key_violation(&self) -> bool

Returns whether the error kind is a violation of a foreign key.

Source

fn is_check_violation(&self) -> bool

Returns whether the error kind is a violation of a check.

Implementations§

Source§

impl dyn DatabaseError

Source

pub fn downcast_ref<E>(&self) -> &E
where E: DatabaseError,

Downcast a reference to this generic database error to a specific database error type.

§Panics

Panics if the database error type is not E. This is a deliberate contrast from Error::downcast_ref which returns Option<&E>. In normal usage, you should know the specific error type. In other cases, use try_downcast_ref.

Source

pub fn downcast<E>(self: Box<dyn DatabaseError>) -> Box<E>
where E: DatabaseError,

Downcast this generic database error to a specific database error type.

§Panics

Panics if the database error type is not E. This is a deliberate contrast from Error::downcast which returns Option<E>. In normal usage, you should know the specific error type. In other cases, use try_downcast.

Source

pub fn try_downcast_ref<E>(&self) -> Option<&E>
where E: DatabaseError,

Downcast a reference to this generic database error to a specific database error type.

Source

pub fn try_downcast<E>( self: Box<dyn DatabaseError>, ) -> Result<Box<E>, Box<dyn DatabaseError>>
where E: DatabaseError,

Downcast this generic database error to a specific database error type.

Trait Implementations§

Source§

impl Error for Box<dyn DatabaseError>

1.30.0 · Source§

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

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl DatabaseError for SqliteError

Source§

fn code(&self) -> Option<Cow<'_, str>>

The extended result code.

Source§

fn message(&self) -> &str

Source§

fn kind(&self) -> ErrorKind

Implementors§