use thiserror::Error;
pub use crate::file_ops::FileError;
#[doc = include_str!("../docs/coding_error.md")]
#[derive(Debug, Error)]
pub enum CodingError {
#[error(transparent)]
File(#[from] FileError),
#[error(transparent)]
Bash(#[from] BashError),
#[error(transparent)]
Grep(#[from] GrepError),
#[error(transparent)]
AstGrep(#[from] AstGrepError),
#[error(transparent)]
Find(#[from] FindError),
#[error(transparent)]
ListFiles(#[from] ListFilesError),
#[error(transparent)]
WebFetch(#[from] WebFetchError),
#[error(transparent)]
WebSearch(#[from] WebSearchError),
#[error("{0}")]
NotConfigured(String),
}
#[derive(Debug, Error)]
pub enum BashError {
#[error("{0}")]
Forbidden(String),
#[error("Timeout cannot exceed 600000ms (10 minutes)")]
TimeoutTooLarge,
#[error("Failed to execute command '{command}': {reason}")]
SpawnFailed { command: String, reason: String },
#[error("Invalid regex pattern: {0}")]
InvalidRegex(String),
#[error("Failed to join background task: {0}")]
JoinFailed(String),
#[error("Shell ID not found: {0}")]
ShellNotFound(String),
#[error("Wait failed: {0}")]
WaitFailed(String),
}
#[derive(Debug, Error)]
pub enum GlobError {
#[error("Invalid glob pattern '{pattern}': {reason}")]
InvalidPattern { pattern: String, reason: String },
#[error("Failed to build glob set: {0}")]
BuildFailed(String),
}
#[derive(Debug, Error)]
pub enum GrepError {
#[error(transparent)]
Glob(#[from] GlobError),
#[error("Invalid regex pattern: {0}")]
InvalidRegex(String),
#[error("Search error: {0}")]
SearchFailed(String),
#[error("Search path does not exist: {0}")]
PathNotFound(String),
}
#[derive(Debug, Error)]
pub enum AstGrepError {
#[error("Search path does not exist: {0}")]
PathNotFound(String),
#[error(transparent)]
Glob(#[from] GlobError),
#[error("Unsupported ast-grep language: {0}")]
UnsupportedLanguage(String),
#[error("Invalid ast-grep pattern: {0}")]
InvalidPattern(String),
#[error("Invalid regex for constraint '{name}': {reason}")]
InvalidConstraintRegex { name: String, reason: String },
#[error("Failed to read file '{path}': {reason}")]
ReadFailed { path: String, reason: String },
#[error("Search error: {0}")]
SearchFailed(String),
}
#[derive(Debug, Error)]
pub enum FindError {
#[error("Search path does not exist: {0}")]
PathNotFound(String),
#[error(transparent)]
Glob(#[from] GlobError),
#[error("Failed to lock results")]
LockFailed,
}
#[derive(Debug, Error)]
pub enum ListFilesError {
#[error("Failed to read directory: {0}")]
ReadDirFailed(String),
#[error("Failed to read entry: {0}")]
ReadEntryFailed(String),
#[error("Failed to read metadata: {0}")]
MetadataFailed(String),
}
#[derive(Debug, Error)]
pub enum WebFetchError {
#[error("Invalid URL: {0}")]
InvalidUrl(String),
#[error("Request failed: {0}")]
RequestFailed(String),
#[error("Request timed out after {0}ms")]
Timeout(u64),
#[error("Response too large: {size} bytes exceeds limit of {limit} bytes")]
ResponseTooLarge { size: usize, limit: usize },
#[error("Failed to parse HTML: {0}")]
ParseFailed(String),
}
#[derive(Debug, Error)]
pub enum WebSearchError {
#[error("Invalid search query: {0}")]
InvalidQuery(String),
#[error("API request failed: {0}")]
ApiError(String),
#[error("Rate limit exceeded: {0}")]
RateLimited(String),
#[error("Request timed out after {0}ms")]
Timeout(u64),
#[error("Configuration error: {0}")]
ConfigError(String),
#[error("Failed to parse API response: {0}")]
ParseError(String),
}