1use std::fmt;
2use std::io;
3use std::path::PathBuf;
4
5#[derive(Debug)]
6pub enum CrabcleanError {
7 Io(io::Error),
8 FileAccess { path: PathBuf, source: io::Error },
9 Config(String),
10 Scan(String),
11 InvalidArgument(String),
12}
13
14impl std::error::Error for CrabcleanError {}
15
16impl fmt::Display for CrabcleanError {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::Io(err) => write!(f, "I/O error: {}", err),
20 Self::FileAccess { path, source } => {
21 write!(f, "Cannot access file '{}': {}", path.display(), source)
22 }
23 Self::Config(msg) => write!(f, "Configuration error: {}", msg),
24 Self::Scan(msg) => write!(f, "File scan error: {}", msg),
25 Self::InvalidArgument(msg) => write!(f, "Invalid argument: {}", msg),
26 }
27 }
28}
29
30impl From<io::Error> for CrabcleanError {
31 fn from(err: io::Error) -> Self {
32 Self::Io(err)
33 }
34}
35
36pub type CrabCleanResult<T> = Result<T, CrabcleanError>;