openpathresolver/
error.rs1#[derive(Debug, thiserror::Error)]
3#[error("{msg}")]
4pub struct Error {
5 msg: String,
6 #[source]
7 source: Option<Box<dyn std::error::Error + Send>>,
8}
9
10macro_rules! impl_from {
11 ($($e:ty: $t:ty => $msg:expr),+ $(,)?) => {
12 $(impl From<$t> for $e {
13 fn from(value: $t) -> Self {
14 Self {
15 msg: $msg.into(),
16 source: Some(Box::new(value)),
17 }
18 }
19 })+
20 };
21}
22
23impl_from!(
24 Error: std::fmt::Error => "Formatting error.",
25 Error: regex::Error => "Error while creating regex.",
26 Error: std::num::TryFromIntError => "Error while converting integer type.",
27 Error: std::num::ParseIntError => "Error while parsing integer.",
28 Error: std::io::Error => "IO Error.",
29 Error: glob::GlobError => "Glob Error.",
30 Error: glob::PatternError => "Glob Pattern Error.",
31 Error: tokio::task::JoinError => "Task Join Error.",
32);
33
34impl Error {
35 pub fn new<T: Into<String>>(msg: T) -> Self {
37 Self {
38 msg: msg.into(),
39 source: None,
40 }
41 }
42}