Skip to main content

evolve_llm/
error.rs

1//! Unified error type for the LLM client crate.
2
3use thiserror::Error;
4
5/// Errors produced by LLM clients.
6#[derive(Debug, Error)]
7pub enum LlmError {
8    /// Environment variable `ANTHROPIC_API_KEY` was not set when an Anthropic
9    /// client was requested.
10    #[error("ANTHROPIC_API_KEY not set")]
11    NoApiKey,
12    /// Transport or TLS failure.
13    #[error("http: {0}")]
14    Http(#[from] reqwest::Error),
15    /// Server returned a non-2xx status after retries were exhausted.
16    #[error("unexpected status {status}: {body}")]
17    UnexpectedStatus {
18        /// HTTP status code.
19        status: u16,
20        /// Body snippet (truncated to 512 chars).
21        body: String,
22    },
23    /// Response body did not match the expected schema.
24    #[error("parse: {0}")]
25    ParseFailure(#[from] serde_json::Error),
26    /// Neither Ollama nor Anthropic was reachable / configured.
27    #[error("no llm available")]
28    NoLlmAvailable,
29}