librmo 0.4.4

A library to manage media files and play them
Documentation
use config::ConfigError;
use lofty::error::LoftyError;
use thiserror::Error;
use sea_orm::DbErr;
use sea_orm::RuntimeErr;
use std::{error::Error, fmt};
use image::ImageError;
use serde;


// A custom error type that represents all possible in our command
#[derive(Debug, Error)]
pub enum CustomError {
    #[error("Failed to read file: {0}")]
    Io(#[from] std::io::Error),
    #[error("File is not valid utf8: {0}")]
    Utf8(#[from] std::string::FromUtf8Error),
    #[error("DB Error: {0}")]
    DBErr(#[from] DbErr),
    #[error("Tag not found: {0}")]
    TagErr(#[from] TagError),
    #[error("SQL Error: {0}")]
    SQLErr(#[from] RuntimeErr),
    #[error("Image Error: {0}")]
    ImgErr(#[from] ImageError),
    #[error("Config Error: {0}")]
    ConfigErr(#[from] ConfigError),
    #[error("Tag error: {0}")]
    TagError(#[from] LoftyError),
    #[error("Query error: {0}")]
    QueryErr(#[from] QueryError),


}

#[derive(Debug, Clone)]
pub struct QueryError{
  pub query: String,
}

impl Error for QueryError {}

impl fmt::Display for QueryError {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
      write!(f, "Query failed: {}", self.query)
  }
}

#[derive(Debug, Clone)]
pub struct TagError{
  pub tag_name: String,
}

impl Error for TagError {}

impl fmt::Display for TagError {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
      write!(f, "Tag not found")
  }
}


// we must also implement serde::Serialize
impl serde::Serialize for CustomError {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  where
    S: serde::ser::Serializer,
  {
    serializer.serialize_str(self.to_string().as_ref())
  }
}
#[derive(Clone, serde::Serialize)]
pub struct Payload {
  pub message: String,
}