use std::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum ArboristError {
FileNotFound { path: String },
UnsupportedLanguage { language: String },
UnrecognizedExtension { extension: String },
LanguageNotEnabled { language: String },
ParseError { details: String },
Io(std::io::Error),
}
impl fmt::Display for ArboristError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ArboristError::FileNotFound { path } => {
write!(f, "file not found: {path}")
}
ArboristError::UnsupportedLanguage { language } => {
write!(f, "unsupported language: {language}")
}
ArboristError::UnrecognizedExtension { extension } => {
write!(f, "unrecognized file extension: {extension}")
}
ArboristError::LanguageNotEnabled { language } => {
write!(
f,
"language '{language}' is recognized but its feature flag is not enabled"
)
}
ArboristError::ParseError { details } => {
write!(f, "parse error: {details}")
}
ArboristError::Io(err) => write!(f, "I/O error: {err}"),
}
}
}
impl std::error::Error for ArboristError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ArboristError::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for ArboristError {
fn from(err: std::io::Error) -> Self {
ArboristError::Io(err)
}
}