Skip to main content

orion_error/core/
mod.rs

1mod case;
2mod context;
3mod domain;
4mod error;
5mod reason;
6mod universal;
7use std::fmt::Display;
8
9pub use context::ContextAdd;
10pub use context::{ContextRecord, OperationContext, OperationScope, WithContext};
11pub use domain::DomainReason;
12pub use error::{convert_error, StructError, StructErrorBuilder, StructErrorTrait};
13pub use reason::ErrorCode;
14pub use universal::{ConfErrReason, UvsFrom, UvsReason};
15
16pub enum ErrStrategy {
17    /// 带退避策略的重试(包含基本参数)
18    Retry,
19    /// 静默忽略错误
20    Ignore,
21    /// 传播错误(默认行为)
22    Throw,
23}
24
25pub fn print_error<R: DomainReason + ErrorCode + Display>(err: &StructError<R>) {
26    println!("[error code{}] \n{err}", err.reason().error_code());
27    for ctx in err.context().iter() {
28        println!("context: {ctx}", ctx = ctx.context());
29    }
30    println!("{}", "-".repeat(50));
31}
32
33pub fn print_error_zh<R: DomainReason + ErrorCode + Display>(err: &StructError<R>) {
34    println!("[错误代码 {}] \n{err}", err.reason().error_code());
35    for ctx in err.context().iter() {
36        println!("上下文: {ctx}", ctx = ctx.context());
37    }
38    println!("{}", "-".repeat(50));
39}