use thiserror::Error;
#[derive(Error, Debug)]
pub enum RalphError {
#[error("Missing API key: {env_var} must be set to use --{provider}")]
MissingApiKey { env_var: String, provider: String },
#[error("Config error: {0}")]
Config(String),
#[error("No provider specified. Use --anthropic, --openai, --deepseek, or --gemini")]
NoProvider,
#[error("LLM API error ({provider}): {message}")]
LlmApi { provider: String, message: String },
#[error("LLM rate limited ({provider}). Retried {attempts} times.")]
LlmRateLimit { provider: String, attempts: u32 },
#[error("LLM authentication failed ({provider}). Check your API key.")]
LlmAuth { provider: String },
#[error("LLM returned malformed tool call: {0}")]
MalformedToolCall(String),
#[error("LLM response was empty or unparseable: {0}")]
LlmResponseParse(String),
#[error("Tool '{tool}' failed: {message}")]
ToolFailed { tool: String, message: String },
#[error("Path is outside the workspace: {0}")]
PathEscape(String),
#[error("File not found: {0}")]
FileNotFound(String),
#[error("Edit failed: old_string not found in {path}")]
EditNotFound { path: String },
#[error("Command blocked by guardrail: {0}")]
BlockedCommand(String),
#[error("Secret detected in generated content — refusing to write")]
SecretDetected,
#[error("Session not found: {0}")]
SessionNotFound(String),
#[error("Session file is corrupt: {0}")]
SessionCorrupt(String),
#[error("Checkpoint not found: {0}")]
CheckpointNotFound(String),
#[error("Checkpoint revert failed: {0}")]
CheckpointRevertFailed(String),
#[error("Max turns ({0}) reached without completing the task")]
MaxTurnsReached(u32),
#[error("Task interrupted by user")]
Interrupted,
#[error("Guardrail violation: {0}")]
GuardrailViolation(String),
#[error("Task aborted by user")]
UserAborted,
#[error("Web search failed: {0}")]
SearchFailed(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
}
pub type Result<T> = std::result::Result<T, RalphError>;