use miette::Diagnostic;
use std::path::PathBuf;
use thiserror::Error;
use super::DotbakError;
#[derive(Debug, Error, Diagnostic)]
pub enum ConfigError {
#[error(transparent)]
#[diagnostic(code(dotbak::error::config::deserialize))]
Deserialize { source: toml::de::Error },
#[error(transparent)]
#[diagnostic(code(dotbak::error::config::serialize))]
Serialize { source: toml::ser::Error },
#[error("The configuration file '{path}' does not exist!")]
#[diagnostic(code(dotbak::error::config::not_found))]
NotFound { path: PathBuf },
#[error("The configuration file '{path}' already exists!")]
#[diagnostic(code(dotbak::error::config::already_exists))]
AlreadyExists { path: PathBuf },
}
impl From<toml::de::Error> for DotbakError {
fn from(err: toml::de::Error) -> Self {
Self::Config(ConfigError::Deserialize { source: err })
}
}
impl From<toml::ser::Error> for DotbakError {
fn from(err: toml::ser::Error) -> Self {
Self::Config(ConfigError::Serialize { source: err })
}
}