use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum DiscoverError {
#[error("IO error while discovering files: {0}")]
Io(#[from] std::io::Error),
#[error("ignore walker error: {0}")]
Walk(#[from] ignore::Error),
#[error("failed to compute relative path for {path} relative to root {root}")]
RelativePath {
path: PathBuf,
root: PathBuf,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn io_variant_displays_message() {
let err = DiscoverError::from(std::io::Error::new(
std::io::ErrorKind::NotFound,
"missing file",
));
let msg = err.to_string();
assert!(msg.contains("IO error"), "got: {msg}");
}
#[test]
fn relative_path_variant_displays_paths() {
let err = DiscoverError::RelativePath {
path: PathBuf::from("/a/b/c.rs"),
root: PathBuf::from("/x"),
};
let msg = err.to_string();
assert!(msg.contains("/a/b/c.rs"), "got: {msg}");
assert!(msg.contains("/x"), "got: {msg}");
assert!(msg.contains("relative path"), "got: {msg}");
}
}