summaryrefslogblamecommitdiff
path: root/src/macro_processor/error.rs
blob: 766115606d1efce28cb02b6e0f5a9c2413054648 (plain) (tree)
1
2
3
4
5
6
7
8
9






                                             
                                                  
                                             










                                                                                   






                                                                  






                                                                                




                                      
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 {}