use std::{fmt, error};
use std::fmt::Formatter;
#[derive(Debug, Eq, PartialEq)]
pub enum UpsError{
Load(LoadError),
Apply(ApplyError),
Create(CreateError),
}
#[derive(Debug, Eq, PartialEq)]
pub enum LoadError{
IsNotUpsFile,
IsCorrupted,
Unknown
}
#[derive(Debug, Eq, PartialEq)]
pub enum ApplyError{
SourceMismatch,
TargetMismatch,
Unknown
}
#[derive(Debug, Eq, PartialEq)]
pub enum CreateError{
Unknown
}
impl fmt::Display for UpsError{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Ups error: {}", self.message())
}
}
impl error::Error for UpsError{}
impl UpsError{
pub fn message(&self) -> &'static str {
match self {
UpsError::Load(load_error) => {match load_error {
LoadError::IsNotUpsFile => "File provided is not a UPS Patch file",
LoadError::IsCorrupted => "FIle provided apears to be corrupted, doesn't match crc32",
_ => "Unknown error during patch load"
}}
UpsError::Apply(apply_error) => { match apply_error {
ApplyError::SourceMismatch => "Source file doesn't match crc32 for source file",
ApplyError::TargetMismatch => "Final target file doesn't match crc32 for target file",
_ => "Unknown error during patch apply"
}}
UpsError::Create(create_error) => {"Unknown Error during patch creation"}
}
}
}