#[derive(Debug)]
pub enum Error {
Io(std::io::Error),
Utf8(std::string::FromUtf8Error),
GifUnknownBlock(u8),
JpegInvalidMarker(u8),
PngChecksum(u32, u32),
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(value: std::string::FromUtf8Error) -> Self {
Self::Utf8(value)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Io(e) => write!(f, "io error: {e}"),
Error::Utf8(e) => write!(f, "tags are not valid utf-8: {e}"),
Error::GifUnknownBlock(b) => write!(f, "unknown gif block found: {b:02X}",),
Error::JpegInvalidMarker(b) => write!(f, "invalid jpeg marker found: {b:02X}"),
Error::PngChecksum(a, b) => write!(f, "corrupted tags in png data: {a:04X} != {b:04X}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Utf8(e) => Some(e),
_ => None,
}
}
}