rustemo_compiler/
error.rs

1pub type Result<R> = std::result::Result<R, Error>;
2
3#[derive(Debug, thiserror::Error)]
4#[error("Rustemo error")]
5pub enum Error {
6    #[error("{0}")]
7    RustemoError(Box<rustemo::Error>),
8
9    #[error("Error: {0}")]
10    Error(String),
11
12    #[error("IOError: {0}")]
13    IOError(#[from] std::io::Error),
14
15    #[error("Syn error: {0}")]
16    SynError(#[from] syn::Error),
17}
18
19impl Error {
20    /// A string representation of the error without the full file path.
21    /// Used in tests to yield the same results at different location.
22    pub fn to_locfile_str(&self) -> String {
23        match self {
24            Error::RustemoError(e) => e.to_pos_str(),
25            Error::SynError(e) => format!("Syn error: {e}"),
26            Error::IOError(e) => format!("IOError: {e}"),
27            Error::Error(e) => format!("Error: {e}"),
28        }
29    }
30}
31
32impl From<rustemo::Error> for Error {
33    fn from(e: rustemo::Error) -> Self {
34        Error::RustemoError(Box::new(e))
35    }
36}