Skip to main content

omni_dev/claude/
error.rs

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