image_reducer/errors/
mod.rs

1pub use std::io::Error as IoError;
2use std::{
3    error::Error,
4    fmt::{Debug, Display, Formatter},
5};
6
7use oxipng::PngError;
8mod for_std;
9mod for_walkdir;
10pub type TinyResult<T = ()> = Result<T, TinyError>;
11
12#[derive(Debug)]
13pub enum TinyError {
14    IoError(String),
15    FormatError(String),
16    TimedOut,
17    ImageOptimized,
18    ChunkError(String),
19    UnknownError,
20}
21
22impl From<PngError> for TinyError {
23    fn from(error: PngError) -> Self {
24        match error {
25            PngError::DeflatedDataTooLong(e) => TinyError::ChunkError(format!("DeflatedDataTooLong {}", e)),
26            PngError::TimedOut => TinyError::TimedOut,
27            PngError::NotPNG => TinyError::FormatError(format!("Except png, found unknown")),
28            PngError::APNGNotSupported => TinyError::ChunkError("APNGNotSupported".to_string()),
29            PngError::InvalidData => TinyError::ChunkError("InvalidData".to_string()),
30            PngError::TruncatedData => TinyError::ChunkError("TruncatedData".to_string()),
31            PngError::ChunkMissing(e) => TinyError::ChunkError(e.to_string()),
32            PngError::Other(e) => TinyError::ChunkError(e.to_string()),
33            _ => panic!("Unsolved error {}", error),
34        }
35    }
36}
37
38impl Display for TinyError {
39    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40        Debug::fmt(self, f)
41    }
42}
43
44impl Error for TinyError {}