Skip to main content

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
9#[cfg(feature = "bedrock")]
10use crate::llm::BedrockError;
11use crate::llm::{AnthropicError, DeepseekError, QwenError};
12
13#[derive(Error, Debug)]
14#[non_exhaustive]
15pub enum LLMError {
16    #[error("OpenAI error: {0}")]
17    OpenAIError(#[from] OpenAIError),
18
19    #[error("Anthropic error: {0}")]
20    AnthropicError(#[from] AnthropicError),
21
22    #[error("Qwen error: {0}")]
23    QwenError(#[from] QwenError),
24
25    #[error("Deepseek error: {0}")]
26    DeepseekError(#[from] DeepseekError),
27
28    #[cfg(feature = "ollama")]
29    #[error("Ollama error: {0}")]
30    OllamaError(#[from] OllamaError),
31
32    #[cfg(feature = "bedrock")]
33    #[error("Bedrock error: {0}")]
34    BedrockError(#[from] BedrockError),
35
36    #[error("Network request failed: {0}")]
37    RequestError(#[from] ReqwestError),
38
39    #[error("JSON serialization/deserialization error: {0}")]
40    SerdeError(#[from] SerdeJsonError),
41
42    #[error("IO error: {0}")]
43    IoError(#[from] std::io::Error),
44
45    #[error("Operation timed out")]
46    Timeout(#[from] Elapsed),
47
48    #[error("Invalid URL: {0}")]
49    InvalidUrl(String),
50
51    #[error("Content not found in response: Expected at {0}")]
52    ContentNotFound(String),
53
54    #[error("Parsing error: {0}")]
55    ParsingError(String),
56
57    #[error("Error: {0}")]
58    OtherError(String),
59}