1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Claude-specific error handling.
use thiserror::Error;
/// Claude API specific errors.
#[derive(Error, Debug)]
pub enum ClaudeError {
/// API key not found in environment variables.
#[error(
"Claude API key not found. Set CLAUDE_API_KEY or ANTHROPIC_API_KEY environment variable"
)]
ApiKeyNotFound,
/// Claude API request failed with error message.
#[error("Claude API request failed: {0}")]
ApiRequestFailed(String),
/// Invalid response format from Claude API.
#[error("Invalid response format from Claude API: {0}")]
InvalidResponseFormat(String),
/// Failed to parse amendments from Claude response.
#[error("Failed to parse amendments from Claude response: {0}")]
AmendmentParsingFailed(String),
/// Prompt exceeds the model's available input token budget.
#[error(
"Prompt too large for model '{model}': estimated {estimated_tokens} tokens, \
but only {max_tokens} input tokens available"
)]
PromptTooLarge {
/// Estimated token count of the assembled prompt.
estimated_tokens: usize,
/// Maximum available input tokens (context minus reserved output).
max_tokens: usize,
/// Model identifier.
model: String,
},
/// Rate limit exceeded for Claude API.
#[error("Rate limit exceeded. Please try again later")]
RateLimitExceeded,
/// Network connectivity error.
#[error("Network error: {0}")]
NetworkError(String),
/// Required subprocess binary is missing from PATH.
#[error("Subprocess binary not found: {0}")]
SubprocessBinaryMissing(String),
/// Failed to spawn a subprocess.
#[error("Failed to spawn subprocess: {0}")]
SubprocessSpawnFailed(String),
/// Subprocess exceeded the configured timeout.
#[error("Subprocess timed out after {secs} seconds")]
SubprocessTimeout {
/// Timeout that was exceeded, in seconds.
secs: u64,
},
/// Subprocess produced more output than the configured cap.
#[error("Subprocess output exceeded limit of {limit} bytes")]
SubprocessOutputTooLarge {
/// Configured stdout cap in bytes.
limit: usize,
},
/// Subprocess stdout was not valid JSON.
#[error("Subprocess produced invalid JSON output: {0}")]
SubprocessJsonParseFailed(String),
}
// Note: anyhow already has a blanket impl for thiserror::Error types