os_bridge/common/
errors.rs

1use std::error::Error;
2use std::fmt::{self};
3use std::fmt::{Debug, Display};
4
5#[derive(Debug, thiserror::Error)]
6pub enum BridgeError {
7  // IO error
8  #[error(transparent)]
9  Io(#[from] std::io::Error),
10
11  // custom error
12  #[allow(unused)]
13  #[error("{0}")]
14  WithMsg(String),
15}
16
17#[allow(unused)]
18impl BridgeError {
19  pub fn new(msg: &str) -> Self {
20    BridgeError::WithMsg(msg.to_string())
21  }
22}
23
24#[derive(Debug)]
25pub struct ErrMsg {
26  pub code: u32,
27  pub msg: String,
28}
29
30//  AppError ro std::fmt::Display traits
31impl fmt::Display for ErrMsg {
32  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33    write!(f, "ErrMsg: {{code:{},msg :{} }}", self.code, self.msg) // user-facing output
34  }
35}
36
37#[allow(unused)]
38pub fn print_err<E>(e: E)
39where
40  E: Display + Debug + Error,
41{
42  print!("{}", e);
43}