summaryrefslogtreecommitdiff
path: root/src/macro_processor/error.rs
blob: cd94c4d98543425949ce4e047c3800b45008a11c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum SMPError {
    IncludeError(u8, std::io::Error, String),
    ShellCommandError(u8, Box<dyn Error>),
    UnknownError(u8, Option<Box<dyn Error>>),
}

impl fmt::Display for SMPError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SMPError::IncludeError(code, _, file) => {
                write!(f, "[SMP{}] Error reading file \"{}\"", code, file)
            }
            SMPError::ShellCommandError(code, e) => {
                write!(f, "[SMP{}] Error running shell command \"{:#?}\"", code, e)
            }
            SMPError::UnknownError(code, e) => {
                write!(
                    f,
                    "[SMP{}] Unknown macro processing error occurred \"{:#?}\"",
                    code, e
                )
            }
        }
    }
}

impl std::error::Error for SMPError {}