use thiserror::Error;
#[derive(Error, Debug)]
pub enum CodeDigestError {
#[error("Invalid path: {0}")]
InvalidPath(String),
#[error("Failed to read file: {0}")]
ReadError(String),
#[error("Failed to write file: {0}")]
WriteError(String),
#[error("Invalid configuration: {0}")]
InvalidConfiguration(String),
#[error("Failed to parse configuration: {0}")]
ConfigParseError(String),
#[error("Configuration file error: {0}")]
ConfigError(String),
#[error("Token counting error: {0}")]
TokenCountError(String),
#[error("Markdown generation error: {0}")]
MarkdownGenerationError(String),
#[error("File prioritization error: {0}")]
PrioritizationError(String),
#[error("{tool} not found. {install_instructions}")]
LlmToolNotFound { tool: String, install_instructions: String },
#[error("Subprocess error: {0}")]
SubprocessError(String),
#[error("File too large: {0} (max: {1} bytes)")]
FileTooLarge(String, usize),
#[error("Token limit exceeded: {current} tokens (max: {max})")]
TokenLimitExceeded { current: usize, max: usize },
#[error("Invalid glob pattern: {0}")]
InvalidGlobPattern(String),
#[error("Remote fetch error: {0}")]
RemoteFetchError(String),
#[error("Clipboard error: {0}")]
ClipboardError(String),
#[error("File processing error for {path}: {error}")]
FileProcessingError { path: String, error: String },
#[error("Token counting error for {path}: {error}")]
TokenCountingError { path: String, error: String },
#[error("Parallel processing errors: {error_count} files failed")]
ParallelProcessingErrors { error_count: usize },
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),
#[error("UTF-8 conversion error: {0}")]
Utf8Error(#[from] std::string::FromUtf8Error),
}
pub type Result<T> = std::result::Result<T, CodeDigestError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = CodeDigestError::InvalidPath("/invalid/path".to_string());
assert_eq!(err.to_string(), "Invalid path: /invalid/path");
let err = CodeDigestError::TokenLimitExceeded { current: 200000, max: 150000 };
assert_eq!(err.to_string(), "Token limit exceeded: 200000 tokens (max: 150000)");
}
#[test]
fn test_io_error_conversion() {
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
let err: CodeDigestError = io_err.into();
assert!(matches!(err, CodeDigestError::IoError(_)));
}
}