use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Configuration file not found: {path}")]
ConfigNotFound { path: PathBuf },
#[error("Invalid configuration: {message}")]
ConfigInvalid { message: String },
#[error("Repository not found: {path}")]
RepoNotFound { path: PathBuf },
#[error("Not a git repository: {path}")]
NotGitRepo { path: PathBuf },
#[error("Git error: {0}")]
Git(#[from] git2::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("No repositories to analyze")]
NoRepositories,
#[error("Repository not found in config: {identifier}")]
RepoNotInConfig { identifier: String },
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = Error::ConfigNotFound {
path: PathBuf::from("/path/to/config.json"),
};
assert!(err.to_string().contains("/path/to/config.json"));
}
#[test]
fn test_error_no_repositories() {
let err = Error::NoRepositories;
assert_eq!(err.to_string(), "No repositories to analyze");
}
#[test]
fn test_error_not_git_repo() {
let err = Error::NotGitRepo {
path: PathBuf::from("/tmp/not-a-repo"),
};
assert!(err.to_string().contains("Not a git repository"));
}
}