use thiserror::Error;
#[derive(Debug, Error)]
pub enum CodingError {
#[error(transparent)]
File(#[from] FileError),
#[error(transparent)]
Bash(#[from] BashError),
#[error(transparent)]
Grep(#[from] GrepError),
#[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 FileError {
#[error("File does not exist: {path}")]
NotFound { path: String },
#[error("Failed to read file {path}: {reason}")]
ReadFailed { path: String, reason: String },
#[error("Failed to write to file {path}: {reason}")]
WriteFailed { path: String, reason: String },
#[error("Failed to create directories for {path}: {reason}")]
CreateDirFailed { path: String, reason: String },
#[error("Invalid offset for file {path}: offset must be 1-indexed (start from 1)")]
InvalidOffset { path: String },
#[error("String replacement failed for file {path}: string '{pattern}' not found")]
PatternNotFound { path: String, pattern: String },
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
#[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 GrepError {
#[error("Invalid glob pattern '{pattern}': {reason}")]
InvalidGlobPattern { pattern: String, reason: String },
#[error("Failed to build glob set: {0}")]
GlobSetBuildFailed(String),
#[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 FindError {
#[error("Search path does not exist: {0}")]
PathNotFound(String),
#[error("Invalid glob pattern '{pattern}': {reason}")]
InvalidGlobPattern { pattern: String, reason: String },
#[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),
}