123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- use crate::image::Pixel;
- use std::error::Error;
- use std::fmt::{Display, Formatter, Result};
- #[derive(Debug)]
- pub struct IncompleteMappingError {
- pub path: std::path::PathBuf,
- pub missing_colors: Vec<Pixel>,
- }
- impl Display for IncompleteMappingError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- writeln!(
- f,
- "`{:?}` is missing entries for the following pixel colors:",
- self.path
- )?;
- for color in self.missing_colors.iter() {
- writeln!(f, " - {:?}", color)?;
- }
- Ok(())
- }
- }
- impl Error for IncompleteMappingError {}
- #[derive(Debug)]
- pub struct ThymeFileStructureError {
- pub message: String,
- }
- impl ThymeFileStructureError {
- pub fn new(msg: impl Into<String>) -> Self {
- ThymeFileStructureError {
- message: msg.into(),
- }
- }
- }
- impl Display for ThymeFileStructureError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- writeln!(f, "{}", self.message)
- }
- }
- impl Error for ThymeFileStructureError {}
- #[derive(Debug)]
- pub enum ThymeFileError {
- StructureError(ThymeFileStructureError),
- ZipError(zip::result::ZipError),
- JsonError(serde_json::Error),
- }
- impl Display for ThymeFileError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- match self {
- ThymeFileError::StructureError(err) => write!(f, "Error parsing file: {}", err),
- ThymeFileError::ZipError(err) => write!(f, "Error with zip wrapper: {}", err),
- ThymeFileError::JsonError(err) => write!(f, "Error parsing JSON: {}", err),
- }
- }
- }
- impl Error for ThymeFileError {}
- impl From<zip::result::ZipError> for ThymeFileError {
- fn from(err: zip::result::ZipError) -> Self {
- ThymeFileError::ZipError(err)
- }
- }
- impl From<serde_json::Error> for ThymeFileError {
- fn from(err: serde_json::Error) -> Self {
- ThymeFileError::JsonError(err)
- }
- }
- impl From<ThymeFileStructureError> for ThymeFileError {
- fn from(err: ThymeFileStructureError) -> Self {
- ThymeFileError::StructureError(err)
- }
- }
|