Skip to main content

DbError

Enum DbError 

Source
pub enum DbError {
Show 21 variants QueryError(String), ConnectionError(String), ConnectionRefused(String), ConnectionTimeout(String), PoolError(PoolError), CacheError(CacheError), TxError(TxError), MigrationError(String), Unsupported(String), ConfigError(String), SerdeError(String), NotFound(String), AlreadyExists(String), ConstraintViolation(String), NullValue(String), InvalidInput(String), Internal(String), IoError(String), Hook(String), TenantError(String), Validation(String),
}
Expand description

数据库错误类型

Variants§

§

QueryError(String)

查询执行失败

§

ConnectionError(String)

连接失败

§

ConnectionRefused(String)

连接被拒绝

§

ConnectionTimeout(String)

连接超时

§

PoolError(PoolError)

连接池错误

§

CacheError(CacheError)

缓存错误

§

TxError(TxError)

事务错误

§

MigrationError(String)

迁移错误

§

Unsupported(String)

方言不支持

§

ConfigError(String)

配置错误

§

SerdeError(String)

序列化/反序列化错误

§

NotFound(String)

未找到

§

AlreadyExists(String)

已存在

§

ConstraintViolation(String)

约束冲突

§

NullValue(String)

非空字段出现 null 值

§

InvalidInput(String)

输入非法

§

Internal(String)

内部错误

§

IoError(String)

IO 错误

§

Hook(String)

钩子执行失败

§

TenantError(String)

多租户错误(如租户 ID 缺失、跨租户访问)

§

Validation(String)

数据验证失败(业务规则校验未通过,由 before_validate 钩子触发)

Implementations§

Source§

impl DbError

Source

pub fn query(s: impl Into<String>) -> Self

新建查询错误

Source

pub fn connection(s: impl Into<String>) -> Self

新建连接错误

Source

pub fn not_found(s: impl Into<String>) -> Self

新建未找到错误

Source

pub fn is_retryable(&self) -> bool

该错误是否可重试

Source

pub fn error_code(&self) -> &'static str

获取错误码(用于日志/监控)

Trait Implementations§

Source§

impl Debug for DbError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DbError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for DbError

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
Source§

impl From<DbError> for LockError

Source§

fn from(e: DbError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for DbError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for DbError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FromUtf8Error> for DbError

Source§

fn from(err: FromUtf8Error) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PoisonError<T>> for DbError

Source§

fn from(err: PoisonError<T>) -> Self

Converts to this type from the input type.
Source§

impl From<TryFromIntError> for DbError

Source§

fn from(err: TryFromIntError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more