use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum CruftError {
#[error("path is not within scan root: {0}")]
PathEscape(PathBuf),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("invalid root: {0}")]
InvalidRoot(String),
#[error("size calculation timed out for: {0}")]
SizeTimeout(PathBuf),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn path_escape_includes_path_in_message() {
let e = CruftError::PathEscape(PathBuf::from("/etc/passwd"));
assert!(e.to_string().contains("/etc/passwd"));
}
#[test]
fn invalid_root_includes_reason() {
let e = CruftError::InvalidRoot("does not exist".into());
assert!(e.to_string().contains("does not exist"));
}
#[test]
fn size_timeout_includes_path() {
let e = CruftError::SizeTimeout(PathBuf::from("/big/tree"));
assert!(e.to_string().contains("/big/tree"));
}
#[test]
fn io_error_converts_via_from() {
let io = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "nope");
let e: CruftError = io.into();
match e {
CruftError::Io(_) => {}
other => panic!("expected Io, got {other:?}"),
}
}
}