From e6ab276a4d5daaf0dd40eed5e2ff477b48187f77 Mon Sep 17 00:00:00 2001 From: Qrius Date: Thu, 26 Sep 2024 00:11:05 +0200 Subject: Change return of MacroProcessor to Result --- src/macro_processor/error.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/macro_processor/error.rs (limited to 'src/macro_processor/error.rs') diff --git a/src/macro_processor/error.rs b/src/macro_processor/error.rs new file mode 100644 index 0000000..074a8ef --- /dev/null +++ b/src/macro_processor/error.rs @@ -0,0 +1,23 @@ +use std::error::Error; +use std::fmt; + +#[derive(Debug)] +pub enum SMPError { + IncludeError(u8, std::io::Error, String), + ShellCommandError(u8, Box), +} + +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) + } + } + } +} + +impl std::error::Error for SMPError {} -- cgit v1.2.3