1use std::path::PathBuf;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, FigifError>;
8
9#[derive(Debug, Error)]
11pub enum FigifError {
12 #[error("failed to read file: {path}")]
14 FileRead {
15 path: PathBuf,
17 #[source]
19 source: std::io::Error,
20 },
21
22 #[error("failed to write file: {path}")]
24 FileWrite {
25 path: PathBuf,
27 #[source]
29 source: std::io::Error,
30 },
31
32 #[error("failed to decode GIF: {reason}")]
34 DecodeError {
35 reason: String,
37 },
38
39 #[error("failed to encode GIF: {reason}")]
41 EncodeError {
42 reason: String,
44 },
45
46 #[error("invalid frame index: {index} (total frames: {total})")]
48 InvalidFrameIndex {
49 index: usize,
51 total: usize,
53 },
54
55 #[error("invalid segment ID: {id} (total segments: {total})")]
57 InvalidSegmentId {
58 id: usize,
60 total: usize,
62 },
63
64 #[error("invalid configuration: {message}")]
66 InvalidConfig {
67 message: String,
69 },
70
71 #[error(
73 "frame dimension mismatch: expected {expected_width}x{expected_height}, got {actual_width}x{actual_height}"
74 )]
75 DimensionMismatch {
76 expected_width: u32,
78 expected_height: u32,
80 actual_width: u32,
82 actual_height: u32,
84 },
85
86 #[error("GIF contains no frames")]
88 NoFrames,
89
90 #[error("image processing error: {reason}")]
92 ImageError {
93 reason: String,
95 },
96
97 #[error("hashing error: {reason}")]
99 HashError {
100 reason: String,
102 },
103
104 #[error("empty or invalid GIF data")]
106 EmptyData,
107}
108
109impl From<gif::DecodingError> for FigifError {
110 fn from(err: gif::DecodingError) -> Self {
111 FigifError::DecodeError {
112 reason: err.to_string(),
113 }
114 }
115}
116
117impl From<image::ImageError> for FigifError {
118 fn from(err: image::ImageError) -> Self {
119 FigifError::ImageError {
120 reason: err.to_string(),
121 }
122 }
123}