use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, FigifError>;
#[derive(Debug, Error)]
pub enum FigifError {
#[error("failed to read file: {path}")]
FileRead {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to write file: {path}")]
FileWrite {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to decode GIF: {reason}")]
DecodeError {
reason: String,
},
#[error("failed to encode GIF: {reason}")]
EncodeError {
reason: String,
},
#[error("invalid frame index: {index} (total frames: {total})")]
InvalidFrameIndex {
index: usize,
total: usize,
},
#[error("invalid segment ID: {id} (total segments: {total})")]
InvalidSegmentId {
id: usize,
total: usize,
},
#[error("invalid configuration: {message}")]
InvalidConfig {
message: String,
},
#[error(
"frame dimension mismatch: expected {expected_width}x{expected_height}, got {actual_width}x{actual_height}"
)]
DimensionMismatch {
expected_width: u32,
expected_height: u32,
actual_width: u32,
actual_height: u32,
},
#[error("GIF contains no frames")]
NoFrames,
#[error("image processing error: {reason}")]
ImageError {
reason: String,
},
#[error("hashing error: {reason}")]
HashError {
reason: String,
},
#[error("empty or invalid GIF data")]
EmptyData,
}
impl From<gif::DecodingError> for FigifError {
fn from(err: gif::DecodingError) -> Self {
FigifError::DecodeError {
reason: err.to_string(),
}
}
}
impl From<image::ImageError> for FigifError {
fn from(err: image::ImageError) -> Self {
FigifError::ImageError {
reason: err.to_string(),
}
}
}