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