use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum ParexError {
#[error("permission denied")]
PermissionDenied(PathBuf),
#[error("path not found")]
NotFound(PathBuf),
#[error("invalid source")]
InvalidSource(PathBuf),
#[error("symlink loop")]
SymlinkLoop(PathBuf),
#[error("invalid pattern")]
InvalidPattern(String),
#[error("invalid thread count")]
InvalidThreadCount(usize),
#[error("thread pool failure")]
ThreadPool(String),
#[error("IO error")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("source error")]
Source(String),
#[error("matcher error")]
Matcher(String),
}
impl ParexError {
pub fn path(&self) -> Option<&PathBuf> {
match self {
Self::PermissionDenied(p)
| Self::NotFound(p)
| Self::InvalidSource(p)
| Self::SymlinkLoop(p)
| Self::Io { path: p, .. } => Some(p),
_ => None,
}
}
pub fn is_recoverable(&self) -> bool {
matches!(
self,
Self::PermissionDenied(_) | Self::SymlinkLoop(_) | Self::Io { .. }
)
}
}