#[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
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
impl DbError
Sourcepub fn code(&self) -> u32
pub fn code(&self) -> u32
稳定错误码(8xxxxx 段,独立于 yang-base 的 BaseError 码命名空间)。
与 DbError::category 同源维护;新增变体需同步补码。
Sourcepub fn category(&self) -> DbErrorCategory
pub fn category(&self) -> DbErrorCategory
引擎级分类。是 DbError::is_retryable 的单一事实源。
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
是否为可重试的瞬时错误(等价 category() == Transient)。
Sourcepub fn is_constraint_violation(&self) -> bool
pub fn is_constraint_violation(&self) -> bool
是否为约束冲突(手工构造的旧变体或结构化 SQLSTATE 的 23 类)。
Sourcepub fn sql_error(&self) -> Option<&SqlErrorInfo>
pub fn sql_error(&self) -> Option<&SqlErrorInfo>
结构化 SQLSTATE 错误信息(仅 DbError::DatabaseError 有值)。
Sourcepub fn constraint(&self) -> Option<&str>
pub fn constraint(&self) -> Option<&str>
触发错误的约束名。
Trait Implementations§
Source§impl Error for DbError
impl Error for DbError
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<Error> for DbError
Available on crate features mysql or postgres only.从 sqlx::Error 转换为 DbError
impl From<Error> for DbError
mysql or postgres only.从 sqlx::Error 转换为 DbError
Source§impl From<PoolError<RedisError>> for DbError
Available on crate feature redis only.从 deadpool_redis::PoolError 转换为 DbError
impl From<PoolError<RedisError>> for DbError
redis only.从 deadpool_redis::PoolError 转换为 DbError
Source§impl From<RedisError> for DbError
Available on crate feature redis only.从 redis::RedisError 转换为 DbError
impl From<RedisError> for DbError
redis only.从 redis::RedisError 转换为 DbError
Source§fn from(err: RedisError) -> Self
fn from(err: RedisError) -> Self
Auto Trait Implementations§
impl Forget for DbError
impl Freeze for DbError
impl Move for DbError
impl RefUnwindSafe for DbError
impl Send for DbError
impl Sync for DbError
impl Unpin for DbError
impl UnsafeUnpin for DbError
impl UnwindSafe for DbError
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
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