Skip to main content

src/errors.rs

1use std::fmt;
2use std::io;
4use image::ImageError;
6#[derive(Debug)]
7pub enum ThumbnailError {
8 MissingFileName,
9 ImageOpenError(ImageError),
10 ImageSaveError(ImageError),
11 CommandFailed(String),
12 Utf8Error(std::str::Utf8Error),
13 PathConversionError,
14 SameInputOutputPath,
15 IoError(std::io::Error),
18impl fmt::Display for ThumbnailError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 ThumbnailError::MissingFileName => write!(f, "Image path is missing a file name"),
22 ThumbnailError::ImageOpenError(e) => write!(f, "Failed to open image: {}", e),
23 ThumbnailError::ImageSaveError(e) => write!(f, "Failed to save thumbnail: {}", e),
24 ThumbnailError::CommandFailed(msg) => write!(f, "ffmpeg command failed: {}", msg),
25 ThumbnailError::Utf8Error(e) => write!(f, "Failed to decode ffmpeg output: {}", e),
26 ThumbnailError::PathConversionError => write!(f, "Failed to convert path to string"),
27 ThumbnailError::SameInputOutputPath => write!(
28 f,
29 "Cannot write thumbnail to the same path as the original image"
30 ),
31 ThumbnailError::IoError(e) => write!(f, "I/O error: {}", e),
32 }
33 }
36impl std::error::Error for ThumbnailError {}
38impl From<ImageError> for ThumbnailError {
39 fn from(err: ImageError) -> Self {
40 ThumbnailError::ImageOpenError(err)
41 }
44impl From<std::str::Utf8Error> for ThumbnailError {
45 fn from(err: std::str::Utf8Error) -> Self {
46 ThumbnailError::Utf8Error(err)
47 }
50impl From<io::Error> for ThumbnailError {
51 fn from(err: io::Error) -> Self {
52 ThumbnailError::IoError(err)
53 }