1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum RalphError {
5 #[error("Missing API key: {env_var} must be set to use --{provider}")]
7 MissingApiKey { env_var: String, provider: String },
8
9 #[error("Config error: {0}")]
10 Config(String),
11
12 #[error("No provider specified. Use --anthropic, --openai, --deepseek, or --gemini")]
13 NoProvider,
14
15 #[error("LLM API error ({provider}): {message}")]
17 LlmApi { provider: String, message: String },
18
19 #[error("LLM rate limited ({provider}). Retried {attempts} times.")]
20 LlmRateLimit { provider: String, attempts: u32 },
21
22 #[error("LLM authentication failed ({provider}). Check your API key.")]
23 LlmAuth { provider: String },
24
25 #[error("LLM returned malformed tool call: {0}")]
26 MalformedToolCall(String),
27
28 #[error("LLM response was empty or unparseable: {0}")]
29 LlmResponseParse(String),
30
31 #[error("Tool '{tool}' failed: {message}")]
33 ToolFailed { tool: String, message: String },
34
35 #[error("Path is outside the workspace: {0}")]
36 PathEscape(String),
37
38 #[error("File not found: {0}")]
39 FileNotFound(String),
40
41 #[error("Edit failed: old_string not found in {path}")]
42 EditNotFound { path: String },
43
44 #[error("Command blocked by guardrail: {0}")]
45 BlockedCommand(String),
46
47 #[error("Secret detected in generated content — refusing to write")]
48 SecretDetected,
49
50 #[error("Session not found: {0}")]
52 SessionNotFound(String),
53
54 #[error("Session file is corrupt: {0}")]
55 SessionCorrupt(String),
56
57 #[error("Checkpoint not found: {0}")]
59 CheckpointNotFound(String),
60
61 #[error("Checkpoint revert failed: {0}")]
62 CheckpointRevertFailed(String),
63
64 #[error("Max turns ({0}) reached without completing the task")]
66 MaxTurnsReached(u32),
67
68 #[error("Task interrupted by user")]
69 Interrupted,
70
71 #[error("Guardrail violation: {0}")]
72 GuardrailViolation(String),
73
74 #[error("Task aborted by user")]
75 UserAborted,
76
77 #[error("Web search failed: {0}")]
79 SearchFailed(String),
80
81 #[error("I/O error: {0}")]
83 Io(#[from] std::io::Error),
84
85 #[error("JSON error: {0}")]
86 Json(#[from] serde_json::Error),
87
88 #[error("HTTP error: {0}")]
89 Http(#[from] reqwest::Error),
90}
91
92pub type Result<T> = std::result::Result<T, RalphError>;