langchain_rust/language_models/
error.rs

1use async_openai::error::OpenAIError;
2#[cfg(feature = "ollama")]
3use ollama_rs::error::OllamaError;
4use reqwest::Error as ReqwestError;
5use serde_json::Error as SerdeJsonError;
6use thiserror::Error;
7use tokio::time::error::Elapsed;
8
9use crate::llm::AnthropicError;
10
11#[derive(Error, Debug)]
12pub enum LLMError {
13    #[error("OpenAI error: {0}")]
14    OpenAIError(#[from] OpenAIError),
15
16    #[error("Anthropic error: {0}")]
17    AnthropicError(#[from] AnthropicError),
18
19    #[cfg(feature = "ollama")]
20    #[error("Ollama error: {0}")]
21    OllamaError(#[from] OllamaError),
22
23    #[error("Network request failed: {0}")]
24    RequestError(#[from] ReqwestError),
25
26    #[error("JSON serialization/deserialization error: {0}")]
27    SerdeError(#[from] SerdeJsonError),
28
29    #[error("IO error: {0}")]
30    IoError(#[from] std::io::Error),
31
32    #[error("Operation timed out")]
33    Timeout(#[from] Elapsed),
34
35    #[error("Invalid URL: {0}")]
36    InvalidUrl(String),
37
38    #[error("Content not found in response: Expected at {0}")]
39    ContentNotFound(String),
40
41    #[error("Error: {0}")]
42    OtherError(String),
43}