#[cfg(feature = "image")]
use image::ImageError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("The image data is empty and cannot be processed.")]
EmptyImageData,
#[error("The image data contains invalid pixel data.")]
InvalidImageData,
#[error("The palette extraction process failed with error: {0}")]
ExtractionFailure(String),
#[error("The algorithm '{0}' is not supported.")]
UnsupportedAlgorithm(String),
#[error("The theme '{0}' is not supported.")]
UnsupportedTheme(String),
#[cfg(feature = "image")]
#[error("The image loading process failed with error: {0}")]
ImageLoadError(#[from] ImageError),
#[cfg(feature = "image")]
#[error("The image format is not supported.")]
UnsupportedImage,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_empty_image_data() {
let actual = Error::EmptyImageData;
assert_eq!(
actual.to_string(),
"The image data is empty and cannot be processed."
);
}
#[test]
fn test_invalid_image_data() {
let actual = Error::InvalidImageData;
assert_eq!(
actual.to_string(),
"The image data contains invalid pixel data."
);
}
#[test]
fn test_extraction_failure() {
let actual = Error::ExtractionFailure("Failed to extract palette.".to_string());
assert_eq!(
actual.to_string(),
"The palette extraction process failed with error: Failed to extract palette."
);
}
#[test]
fn test_unsupported_algorithm() {
let actual = Error::UnsupportedAlgorithm("unknown_algorithm".to_string());
assert_eq!(
actual.to_string(),
"The algorithm 'unknown_algorithm' is not supported."
);
}
#[test]
fn test_unsupported_theme() {
let actual = Error::UnsupportedTheme("unknown_theme".to_string());
assert_eq!(
actual.to_string(),
"The theme 'unknown_theme' is not supported."
);
}
#[test]
#[cfg(feature = "image")]
fn test_image_load_error() {
let cause = ImageError::IoError(std::io::Error::from(std::io::ErrorKind::NotFound));
let error = Error::ImageLoadError(cause);
let actual = error.to_string();
assert_eq!(
actual,
"The image loading process failed with error: entity not found"
);
}
#[test]
#[cfg(feature = "image")]
fn test_unsupported_image() {
let actual = Error::UnsupportedImage;
assert_eq!(actual.to_string(), "The image format is not supported.");
}
}