Added default formatters + error handling
This commit is contained in:
8 files changed
+337
-21
No files matched your search
@@ -0,0 +1,47 @@
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use crate::parser::ByteArrayParseErr;
|
||||
use crate::formatter::format::FormatError;
|
||||
use crate::formatter::FormatConfigError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FormatyError {
|
||||
ByteArrayParseError(ByteArrayParseErr),
|
||||
FormatError(FormatError),
|
||||
FormatConfigError(FormatConfigError),
|
||||
FormatNotFound(String)
|
||||
|
||||
}
|
||||
|
||||
impl From<ByteArrayParseErr> for FormatyError {
|
||||
fn from(e: ByteArrayParseErr) -> Self {
|
||||
Self::ByteArrayParseError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FormatError> for FormatyError {
|
||||
fn from(e: FormatError) -> Self {
|
||||
Self::FormatError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FormatConfigError> for FormatyError {
|
||||
fn from(e: FormatConfigError) -> Self {
|
||||
Self::FormatConfigError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FormatyError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let err_msg = match self {
|
||||
FormatyError::ByteArrayParseError(e) => e.to_string(),
|
||||
FormatyError::FormatError(e) => e.to_string(),
|
||||
FormatyError::FormatConfigError(e) => e.to_string(),
|
||||
FormatyError::FormatNotFound(err_msg) => format!("'{}' config not found.", err_msg)
|
||||
};
|
||||
|
||||
write!(f, "{}", err_msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for FormatyError {}
|
||||
Reference in new issue
Block a user