use thiserror::Error;
#[derive(Error, Debug)]
pub enum HooksmithError {
#[error("Configuration error: {0}")]
Config(#[from] ConfigError),
#[error("Git error: {0}")]
Git(#[from] GitError),
#[error("Hook execution error: {0}")]
HookExecution(#[from] HookExecutionError),
#[error("Validation error: {0}")]
Validation(#[from] ValidationError),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("Failed to read config file: {0}")]
Io(#[from] std::io::Error),
#[error("Failed to parse config file: {0}")]
Parse(#[from] serde_yaml::Error),
#[error("Config file not found at: {0}")]
NotFound(String),
}
#[derive(Error, Debug)]
pub enum GitError {
#[error("Failed to execute git command: {0}")]
Command(#[from] std::io::Error),
#[error("Git hooks directory not found")]
HooksDirNotFound,
#[error("Not a git repository")]
NotGitRepo,
}
#[derive(Error, Debug)]
pub enum HookExecutionError {
#[error("Failed to execute command: {0}")]
Command(#[from] std::io::Error),
#[error("Command failed with status code: {0}")]
CommandFailed(i32),
#[error("Hook not found: {0}")]
HookNotFound(String),
}
#[derive(Error, Debug)]
pub enum ValidationError {
#[error("Invalid hook name: {0}")]
InvalidHookName(String),
#[error("Invalid command: {0}")]
InvalidCommand(String),
}
pub type Result<T> = std::result::Result<T, HooksmithError>;