use std::{fmt::Display, io, path::PathBuf}; use thiserror::Error; pub type Result = std::result::Result; #[derive(Error, Debug)] pub enum Error { ConfigParse { file: PathBuf, error: serde_json::Error, }, ConfigRead { file: PathBuf, error: io::Error, }, RepoOpen { repository_path: PathBuf, error: Box, }, RocketLaunch(#[from] rocket::Error), } impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Error::ConfigParse { file, error } => { write!( f, "while trying to parse the config file ({}): {error}", file.display() ) } Error::ConfigRead { file, error } => { write!( f, "while trying to read the config file ({}): {error}", file.display() ) } Error::RepoOpen { repository_path, error, } => { write!( f, "while trying to open the repository ({}): {error}", repository_path.display() ) } Error::RocketLaunch(error) => { write!(f, "while trying to start back: {error}") } } } }