fuels_code_gen/
error.rs

1use std::{
2    fmt::{Debug, Display, Formatter},
3    io,
4};
5
6pub struct Error(pub String);
7
8impl Error {
9    pub fn combine<T: Into<Self>>(self, err: T) -> Self {
10        error!("{} {}", self.0, err.into().0)
11    }
12}
13
14#[macro_export]
15macro_rules! error {
16   ($fmt_str: literal $(,$arg: expr)*) => {$crate::error::Error(format!($fmt_str,$($arg),*))}
17}
18
19pub use error;
20
21pub type Result<T> = std::result::Result<T, Error>;
22
23impl Debug for Error {
24    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25        write!(f, "{:?}", self.0)
26    }
27}
28
29impl Display for Error {
30    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31        write!(f, "{}", self.0)
32    }
33}
34
35impl std::error::Error for Error {}
36
37macro_rules! impl_from {
38    ($($err_type:ty),*) => {
39        $(
40            impl From<$err_type> for self::Error {
41                fn from(err: $err_type) -> Self {
42                    Self(err.to_string())
43                }
44            }
45        )*
46    }
47}
48
49impl_from!(
50    serde_json::Error,
51    io::Error,
52    proc_macro2::LexError,
53    fuel_abi_types::error::Error
54);