summaryrefslogtreecommitdiff
path: root/src/macro_processor/error.rs
blob: 766115606d1efce28cb02b6e0f5a9c2413054648 (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
32
33
34
35
36
37
38
39
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum SMPError {
    IncludeError(u8, std::io::Error, String),
    ShellCommandError(u8, Box<dyn Error>),
    MarkdownError(u8, markdown::message::Message),
    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::MarkdownError(code, message) => {
                write!(
                    f,
                    "[SMP{}] Error converting markdown \"{:#?}\"",
                    code, message
                )
            }
            SMPError::UnknownError(code, e) => {
                write!(
                    f,
                    "[SMP{}] Unknown macro processing error occurred \"{:#?}\"",
                    code, e
                )
            }
        }
    }
}

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