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
49// Note: anyhow already has a blanket impl for thiserror::Error types