use crate::env_config::parse::EnvConfigParseError;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub enum EnvConfigFileLoadError {
#[non_exhaustive]
ParseError(EnvConfigParseError),
#[non_exhaustive]
CouldNotReadFile(CouldNotReadConfigFile),
}
impl Display for EnvConfigFileLoadError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
EnvConfigFileLoadError::ParseError(_err) => {
write!(f, "could not parse profile file")
}
EnvConfigFileLoadError::CouldNotReadFile(err) => {
write!(f, "could not read file `{}`", err.path.display())
}
}
}
}
impl Error for EnvConfigFileLoadError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
EnvConfigFileLoadError::ParseError(err) => Some(err),
EnvConfigFileLoadError::CouldNotReadFile(details) => Some(&details.cause),
}
}
}
impl From<EnvConfigParseError> for EnvConfigFileLoadError {
fn from(err: EnvConfigParseError) -> Self {
EnvConfigFileLoadError::ParseError(err)
}
}
#[derive(Debug, Clone)]
pub struct CouldNotReadConfigFile {
pub(crate) path: PathBuf,
pub(crate) cause: Arc<std::io::Error>,
}