#[non_exhaustive]pub enum BaseError {
Show 66 variants
PluginAlreadyRegistered(String),
PluginNotFound(String),
PluginRegisterFailed(String, String),
PluginInitFailed(String, String),
PluginDependencyMissing(String, String),
PluginCircularDependency(String),
PluginConfigInvalid(String, String),
PluginShutdownFailed(String, String),
PluginLifecycleFailed {
plugin: String,
stage: PluginLifecycleStage,
source: PluginError,
},
DatabaseConnectionFailed(DbError),
DatabaseConnectionDbError(DbError),
DatabaseAlreadyInitialized,
DatabaseQueryFailed(DbError),
DatabaseExecuteFailed(DbError),
DatabaseInitFailed(String),
DatabaseMigrationFailed(String, String),
MigrationFailed(String, String, String),
MigrationExecutionFailed {
module: String,
version: String,
checksum: String,
source: DbError,
},
MigrationChecksumMismatch {
module: String,
version: String,
expected: String,
actual: Option<String>,
},
MigrationInProgress {
module: String,
version: String,
},
DatabaseNotInitialized,
DatabaseTransactionFailed(DbError),
MissingWhereClause(String),
RedisConnectionFailed(DbError),
RedisAlreadyInitialized,
RedisNotInitialized,
RedisOperationFailed(DbError),
RedisOperationDbError(DbError),
HttpClientCreateFailed(Error),
HttpRequestFailed(Error),
HttpResponseParseFailed(String),
HttpTimeout,
HttpClientAlreadyInitialized,
HttpClientNotInitialized,
HttpCircuitBreakerOpen(String),
TokenKeyInvalid(String),
TokenGenerateFailed(Error),
TokenVerifyFailed(Error),
TokenParseFailed(Error),
TokenExpired,
TokenRevoked,
TokenTypeInvalid(String),
JsonSerializeFailed(String),
JsonDeserializeFailed(String),
InvalidFieldType(String, String),
InvalidEnumValue(String, String),
StringTooLong(String, usize, usize),
InvalidJsonFormat(String, String),
ValidationFailed(String, String),
FieldRequired(String),
FieldNotFound(String, String),
FieldPermissionDenied(String, String, String),
ActionNotFound(String),
PermissionDenied(String),
Unauthorized(String),
ParamMissing(String),
ParamInvalid(String, String),
RateLimitExceeded {
retry_after_seconds: u64,
},
RecordNotFound(String),
UserNotFound(String),
InvalidPassword,
TableDefinitionNotSet,
StepUpRequired(StepUpChallenge),
ConfigError(String),
IoError(String),
Unknown(String),
}Expand description
系统统一错误类型
包含所有模块的错误变体,使用中文错误消息
标注 #[non_exhaustive]:未来新增变体不构成跨 crate 破坏性变更(下游 match 需
带 _ 臂)。同 crate 内的穷举 match(code()/code_str()/category())不受
影响,新增变体时 test_code_str_matches_code 测试会捕获漏编。
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
PluginAlreadyRegistered(String)
插件已注册
PluginNotFound(String)
插件未找到
PluginRegisterFailed(String, String)
插件注册失败
PluginInitFailed(String, String)
插件初始化失败
PluginDependencyMissing(String, String)
插件依赖缺失
PluginCircularDependency(String)
插件循环依赖
PluginConfigInvalid(String, String)
插件配置无效
PluginShutdownFailed(String, String)
插件关闭失败
PluginLifecycleFailed
插件生命周期回调失败,保留插件名、阶段与底层错误链。
DatabaseConnectionFailed(DbError)
数据库连接失败,持有底层 DbError 以保留错误链
DatabaseConnectionDbError(DbError)
数据库连接失败(DbError 专用变体,用于 From<DbError> 映射)
与 DatabaseConnectionFailed 语义相同但独立编码 200011,
便于下游区分“直接构造的连接错误“和“来自 DbError 包装的连接错误“。
DatabaseAlreadyInitialized
数据库已初始化
DatabaseQueryFailed(DbError)
数据库查询失败,持有底层 DbError 以保留错误链
DatabaseExecuteFailed(DbError)
数据库执行失败,持有底层 DbError 以保留错误链
DatabaseInitFailed(String)
数据库初始化失败
DatabaseMigrationFailed(String, String)
数据库迁移失败
MigrationFailed(String, String, String)
迁移失败(别名)
MigrationExecutionFailed
迁移 SQL 执行失败,保留迁移身份、内容校验和与底层数据库错误链。
Fields
MigrationChecksumMismatch
已执行迁移的内容与当前声明不一致。
Fields
MigrationInProgress
同一迁移已被另一个初始化器预留。
DatabaseNotInitialized
数据库未初始化
DatabaseTransactionFailed(DbError)
数据库事务失败,持有底层 DbError 以保留错误链
MissingWhereClause(String)
UPDATE/DELETE 缺少 WHERE 条件,拒绝全表操作
与 yang-db 的 MissingWhereClause 安全网对齐:无 WHERE 的更新/删除
始终被拒绝,以防止误操作整表。
RedisConnectionFailed(DbError)
Redis 连接失败,持有底层 DbError 以保留错误链。
RedisAlreadyInitialized
Redis 已初始化
RedisNotInitialized
Redis 未初始化
RedisOperationFailed(DbError)
Redis 操作失败,持有底层 DbError 以保留错误链。
RedisOperationDbError(DbError)
Redis 操作失败,持有底层 DbError 以保留错误链
HttpClientCreateFailed(Error)
HTTP 客户端创建失败,持有底层 reqwest::Error 以保留错误链
HttpRequestFailed(Error)
HTTP 请求失败,持有底层 reqwest::Error 以保留错误链
HttpResponseParseFailed(String)
HTTP 响应解析失败
HttpTimeout
HTTP 超时
HttpClientAlreadyInitialized
HTTP 客户端已初始化
HttpClientNotInitialized
HTTP 客户端未初始化
HttpCircuitBreakerOpen(String)
HTTP 熔断器打开:目标 host 近期连续失败,请求被快速拒绝
TokenKeyInvalid(String)
Token 密钥无效
TokenGenerateFailed(Error)
Token 生成失败,持有底层 jsonwebtoken::errors::Error 以保留错误链
TokenVerifyFailed(Error)
Token 验证失败,持有底层 jsonwebtoken::errors::Error 以保留错误链
TokenParseFailed(Error)
Token 解析失败,持有底层 jsonwebtoken::errors::Error 以保留错误链
TokenExpired
Token 已过期
TokenRevoked
Token 已被撤销(命中黑名单)
TokenTypeInvalid(String)
Token 类型无效
JsonSerializeFailed(String)
JSON 序列化失败
JsonDeserializeFailed(String)
JSON 反序列化失败
InvalidFieldType(String, String)
字段类型无效
InvalidEnumValue(String, String)
枚举值无效
StringTooLong(String, usize, usize)
字符串长度超出限制
InvalidJsonFormat(String, String)
JSON 格式无效
ValidationFailed(String, String)
验证失败
FieldRequired(String)
字段必填
FieldNotFound(String, String)
字段未找到
FieldPermissionDenied(String, String, String)
字段权限被拒绝
ActionNotFound(String)
Action 未找到
PermissionDenied(String)
权限被拒绝
未授权
ParamMissing(String)
参数缺失
ParamInvalid(String, String)
参数无效
RateLimitExceeded
请求超过速率限制。
RecordNotFound(String)
记录未找到
UserNotFound(String)
用户未找到
InvalidPassword
密码无效
TableDefinitionNotSet
表定义未设置
StepUpRequired(StepUpChallenge)
敏感 Action 尚未完成短期重认证。
ConfigError(String)
配置错误
IoError(String)
IO 错误
Unknown(String)
未知错误
Implementations§
Source§impl BaseError
impl BaseError
Sourcepub fn code(&self) -> i32
pub fn code(&self) -> i32
获取错误码
返回与错误类型对应的数字错误码,用于 API 响应
§错误码规范
- 1xxxxx: 插件管理错误
- 2xxxxx: 数据库错误
- 21xxxx: Redis 错误(隶属数据库 2xxxxx 大类)
- 3xxxxx: HTTP 客户端错误
- 4xxxxx: Token 管理错误
- 5xxxxx: 序列化错误
- 6xxxxx: 字段验证错误
- 7xxxxx: Action 系统错误
- 9xxxxx: 通用错误
§返回
- 错误码(非零整数)
§示例
use yang_base::error::BaseError;
let error = BaseError::FieldRequired("username".to_string());
assert_eq!(error.code(), 600006);Sourcepub fn code_str(&self) -> &'static str
pub fn code_str(&self) -> &'static str
返回错误码的 &'static str 形式,供 metrics label 使用(零分配、低基数)。
与 BaseError::code 一一对应:code_str() 是 code() 的字符串字面量版本,
专用于 metrics 的 label(label 必须是 &'static str,严禁 code().to_string()
造成每次派发堆分配 + 高基数)。新增变体时两者需同步维护,并由
test_code_str_matches_code 守护一致性。
Sourcepub fn category(&self) -> ErrorCategory
pub fn category(&self) -> ErrorCategory
引擎级错误分类(弹性重试与任意下游适配的共同基座)。
返回 ErrorCategory,是 is_retryable / is_client_error /
is_server_error 的单一事实源。分类语义为引擎自有,与具体 HTTP status
映射无关——HTTP 映射属调用方传输层边界。
Transient 在 is_server_error 中视为服务端错误(但可重试),
在 is_client_error 中不视为客户端错误。Auth 和 NotFound 在
is_client_error 中视为客户端错误(认证/授权失败和资源不存在均归调用方过错)。
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
是否为可重试的瞬时错误(等价 category() == Transient)。
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
是否为客户端过错(Client、Auth 或 NotFound 类)。
用于下游统一适配——客户端过错不可重试,调用方应修正请求而非重试。
注意 Transient 不在此列:虽然瞬时错误也可归「服务端」,但它不是
调用方过错,且可重试——is_server_error 已覆盖该语义。
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
是否为服务端/基础设施错误(Server、Transient 或 Conflict)。
用于下游统一适配。Transient 在此视为服务端(可重试的服务端错误,
如连接超时 = HTTP 503 语义);Conflict 也计入(资源冲突 = HTTP 409,
但常由并发写引起而非纯调用方过错)。
Trait Implementations§
Source§impl Error for BaseError
impl Error for BaseError
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<DbError> for BaseError
从 yang_db::DbError 转换为 BaseError
impl From<DbError> for BaseError
从 yang_db::DbError 转换为 BaseError
按 DbError 变体分类映射到对应的 BaseError 变体:
- 查询类 → DatabaseQueryFailed
- 执行类 → DatabaseExecuteFailed
- 事务类 → DatabaseTransactionFailed
- 连接类 → DatabaseConnectionFailed(包装 DbError 保留错误链)
- Redis 连接类 → RedisConnectionFailed
- Redis 其他操作类 → RedisOperationFailed
Source§impl From<Error> for BaseError
Available on crate feature http only.从 reqwest::Error 转换为 BaseError
impl From<Error> for BaseError
http only.从 reqwest::Error 转换为 BaseError
Auto Trait Implementations§
impl !RefUnwindSafe for BaseError
impl !UnwindSafe for BaseError
impl Freeze for BaseError
impl Send for BaseError
impl Sync for BaseError
impl Unpin for BaseError
impl UnsafeUnpin for BaseError
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