Skip to main content

DbError

Enum DbError 

Source
#[non_exhaustive]
pub enum DbError {
Show 23 variants ConnectionError(String), QueryError(String), SqlSyntaxError(String), ConstraintError(String), TypeConversionError(String), SerializationError(String), DeserializationError(String), TransactionError(String), TableNotFound(String), MissingWhereClause, RedisConnectionError(String), RedisCommandError(String), RedisPoolError(String), RedisTypeConversionError(String), RedisTimeoutError(String), RedisError(RedisErrorInfo), RedisPoolClosed, MissingGroupByClause, UnsupportedOperator(String), InvalidArgument(String), Unknown(String), PoolClosed, DatabaseError(Box<SqlErrorInfo>),
}
Expand description

数据库错误类型

标注 #[non_exhaustive]:未来新增变体不构成跨 crate 破坏性变更(下游 match 需 带 _ 臂)。同 crate 内的穷举 match 不受影响。

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

ConnectionError(String)

§

QueryError(String)

§

SqlSyntaxError(String)

§

ConstraintError(String)

§

TypeConversionError(String)

§

SerializationError(String)

§

DeserializationError(String)

§

TransactionError(String)

§

TableNotFound(String)

§

MissingWhereClause

§

RedisConnectionError(String)

§

RedisCommandError(String)

§

RedisPoolError(String)

§

RedisTypeConversionError(String)

§

RedisTimeoutError(String)

§

RedisError(RedisErrorInfo)

结构化 Redis 错误:保留协议层 ErrorKind 与重试建议,避免把 LOADING/TRYAGAIN/NOSCRIPT 等可重试错误压成不可重试的字符串。

§

RedisPoolClosed

Redis 连接池已关闭(不可重试)。

§

MissingGroupByClause

§

UnsupportedOperator(String)

不支持的操作符错误,当传入的操作符不在支持集合中时返回

§

InvalidArgument(String)

参数非法(调用方过错):批量数据列集不一致、空数据、batch_size 为 0 等。

与 DbError::SerializationError 区分——后者专表「(反)序列化失败」, 此变体专表「入参本身不合法」,便于调用方按变体精确分流(DB-14)。

§

Unknown(String)

§

PoolClosed

连接池已关闭(非瞬时错误,不应重试)。

§

DatabaseError(Box<SqlErrorInfo>)

携带 SQLSTATE 与约束元数据的结构化数据库错误。

sqlx::Error::Database 一律映射到本变体,便于下游按 SqlErrorInfo::kind / SqlErrorInfo::code 精确分流, 而不是解析本地化报文。旧的字符串变体保留用于手工构造与向后兼容。

Implementations§

Source§

impl DbError

Source

pub fn code(&self) -> u32

稳定错误码(8xxxxx 段,独立于 yang-base 的 BaseError 码命名空间)。

与 DbError::category 同源维护;新增变体需同步补码。

Source

pub fn category(&self) -> DbErrorCategory

引擎级分类。是 DbError::is_retryable 的单一事实源。

Source

pub fn is_retryable(&self) -> bool

是否为可重试的瞬时错误(等价 category() == Transient)。

Source

pub fn is_constraint_violation(&self) -> bool

是否为约束冲突(手工构造的旧变体或结构化 SQLSTATE 的 23 类)。

Source

pub fn sql_error(&self) -> Option<&SqlErrorInfo>

结构化 SQLSTATE 错误信息(仅 DbError::DatabaseError 有值)。

Source

pub fn sqlstate(&self) -> Option<&str>

原始 SQLSTATE 码。

Source

pub fn constraint(&self) -> Option<&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, __formatter: &mut Formatter<'_>) -> Result

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

impl Error for DbError

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

impl From<Error> for DbError

Available on crate features mysql or postgres only.

从 sqlx::Error 转换为 DbError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<PoolError<RedisError>> for DbError

Available on crate feature redis only.

从 deadpool_redis::PoolError 转换为 DbError

Source§

fn from(err: PoolError) -> Self

Converts to this type from the input type.
Source§

impl From<RedisError> for DbError

Available on crate feature redis only.

从 redis::RedisError 转换为 DbError

Source§

fn from(err: RedisError) -> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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