pub enum CliError {
Io(Error),
Json(Error),
Wal(WalError),
RulesDirNotFound(String),
NoRulesFound(String),
InvalidPayload(String),
FactLogParse {
line: usize,
reason: String,
},
HashChain(String),
ExecutionHadErrors {
count: usize,
},
Other(String),
}Expand description
CLI 错误
设计原则:
- 每个变体携带足够上下文(路径、行号、原因),便于用户定位问题
#[from]自动转换 std::io::Error / serde_json::Error / WalError- Display 输出人类可读的中文/英文混合消息(与现有 CLI 风格一致)
Variants§
Io(Error)
文件系统 I/O 错误
Json(Error)
JSON 序列化/反序列化错误
Wal(WalError)
tier1 WAL 序列化错误(fact_from_json 失败等)
RulesDirNotFound(String)
规则目录不存在
NoRulesFound(String)
规则目录中无 .json 文件
InvalidPayload(String)
初始 payload JSON 解析失败
FactLogParse
fact log 解析错误(指定行号和原因)
HashChain(String)
哈希链验证失败
ExecutionHadErrors
执行完成但产生 Error 事实(规则执行失败)
CR-20260902-001(UV-046 C1/C3):执行含 Error fact 时不再返回退出码 0。 CI/自动化管道以退出码判定成败,Error fact 静默成功会让“确定性执行“ 的核心承诺在自动化场景下失效。fact log 仍正常写出供审计。
Other(String)
通用错误(兜底)
Implementations§
Source§impl CliError
退出码映射
impl CliError
退出码映射
约定:
- 0:成功
- 1:通用错误(默认)
- 2:规则加载错误(目录不存在、无 .json)
- 3:执行完成但产生 Error 事实(CR-20260902-001:不再静默成功)
Sourcepub fn exit_code(&self) -> i32
pub fn exit_code(&self) -> i32
返回该错误对应的退出码
§约定
- 0:成功
- 1:通用错误(默认)
- 2:规则加载错误(目录不存在、无 .json)
- 3:执行完成但产生 Error 事实(CR-20260902-001)
§示例
use evorule_cli::CliError;
// 规则目录缺失 → 退出码 2
let dir_err = CliError::RulesDirNotFound("/nonexistent".into());
assert_eq!(dir_err.exit_code(), 2);
// 执行含 Error fact → 退出码 3
let exec_err = CliError::ExecutionHadErrors { count: 1 };
assert_eq!(exec_err.exit_code(), 3);
// 通用错误 → 退出码 1
assert_eq!(CliError::other("boom").exit_code(), 1);Trait Implementations§
Source§impl Error for CliError
impl Error for CliError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for CliError
impl !UnwindSafe for CliError
impl Freeze for CliError
impl Send for CliError
impl Sync for CliError
impl Unpin for CliError
impl UnsafeUnpin for CliError
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
Mutably borrows from an owned value. Read more