pub use lc_providers::ollama::OllamaError;
pub use lc_providers::openai::responses::types::ResponsesError;
pub use lc_providers::openai::AssistantError;
pub use lc_providers::openai::OpenAIError;
pub use lc_providers::providers::anthropic::error::AnthropicError;
pub use lc_providers::providers::gemini::GeminiError;
pub use lc_agents::crag::grader::GraderError;
pub use lc_agents::crag::rewriter::RewriterError;
pub use lc_agents::handoffs::handoff::HandoffError;
pub use lc_agents::AdaptiveRAGError;
pub use lc_agents::AgentError;
pub use lc_agents::CRAGError;
pub use lc_agents::PlanExecuteError;
pub use lc_agents::ResearchError;
pub use lc_chains::ChainError;
pub use lc_core::batch::BatchError;
pub use lc_core::json_parse::LlmJsonParseError;
pub use lc_core::math::MathError;
pub use lc_core::output_parsers::OutputParserError;
pub use lc_core::router_llm::RouterError;
pub use lc_core::structured_output::extract::StructuredOutputError;
pub use lc_core::structured_output::parser::PartialJsonError;
pub use lc_core::tools::ToolError;
pub use lc_embeddings::EmbeddingError;
pub use lc_memory::base::MemoryError;
pub use lc_rag::graph_rag::GraphRAGError;
pub use lc_rag::hyde::HyDEError;
pub use lc_rag::multi_query::MultiQueryError;
pub use lc_rag::reranking::RerankingError;
pub use lc_rag::LoaderError;
pub use lc_rag::RetrieverError;
pub use lc_vector_stores::VectorStoreError;
pub use lc_tools::sandbox::SandboxError;
pub use lc_callbacks::LangSmithError;
pub use lc_langgraph::errors::GraphError;
pub use lc_langgraph::PersistenceError;
pub use lc_guardrails::GuardrailError;
pub use lc_evaluation::EvalError;
pub use lc_sessions::store::SessionError;
pub use lc_a2a::client::A2AError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("OpenAI error: {0}")]
OpenAI(#[from] OpenAIError),
#[error("Anthropic error: {0}")]
Anthropic(#[from] AnthropicError),
#[error("Gemini error: {0}")]
Gemini(#[from] GeminiError),
#[error("Ollama error: {0}")]
Ollama(#[from] OllamaError),
#[error("Assistant error: {0}")]
Assistant(#[from] AssistantError),
#[error("Responses error: {0}")]
Responses(#[from] ResponsesError),
#[error("Provider error: {0}")]
Provider(#[from] lc_providers::ProviderError),
#[error("AdaptiveRAG error: {0}")]
AdaptiveRAG(#[from] AdaptiveRAGError),
#[error("Agent error: {0}")]
Agent(#[from] AgentError),
#[error("CRAG error: {0}")]
CRAG(#[from] CRAGError),
#[error("Grader error: {0}")]
Grader(#[from] GraderError),
#[error("Rewriter error: {0}")]
Rewriter(#[from] RewriterError),
#[error("Research error: {0}")]
Research(#[from] ResearchError),
#[error("Handoff error: {0}")]
Handoff(#[from] HandoffError),
#[error("PlanExecute error: {0}")]
PlanExecute(#[from] PlanExecuteError),
#[error("Chain error: {0}")]
Chain(#[from] ChainError),
#[error("Batch error: {0}")]
Batch(#[from] BatchError),
#[error("LlmJsonParse error: {0}")]
LlmJsonParse(#[from] LlmJsonParseError),
#[error("Math error: {0}")]
Math(#[from] MathError),
#[error("OutputParser error: {0}")]
OutputParser(#[from] OutputParserError),
#[error("Router error: {0}")]
Router(#[from] RouterError),
#[error("StructuredOutput error: {0}")]
StructuredOutput(#[from] StructuredOutputError),
#[error("PartialJson error: {0}")]
PartialJson(#[from] PartialJsonError),
#[error("Tool error: {0}")]
Tool(#[from] ToolError),
#[error("Embedding error: {0}")]
Embedding(#[from] EmbeddingError),
#[error("Memory error: {0}")]
Memory(#[from] MemoryError),
#[error("GraphRAG error: {0}")]
GraphRAG(#[from] GraphRAGError),
#[error("HyDE error: {0}")]
HyDE(#[from] HyDEError),
#[error("Loader error: {0}")]
Loader(#[from] LoaderError),
#[error("MultiQuery error: {0}")]
MultiQuery(#[from] MultiQueryError),
#[error("Reranking error: {0}")]
Reranking(#[from] RerankingError),
#[error("Retriever error: {0}")]
Retriever(#[from] RetrieverError),
#[error("VectorStore error: {0}")]
VectorStore(#[from] VectorStoreError),
#[error("Sandbox error: {0}")]
Sandbox(#[from] SandboxError),
#[error("LangSmith error: {0}")]
LangSmith(#[from] LangSmithError),
#[error("Graph error: {0}")]
Graph(#[from] GraphError),
#[error("Persistence error: {0}")]
Persistence(#[from] PersistenceError),
#[error("Guardrail error: {0}")]
Guardrail(#[from] GuardrailError),
#[error("Eval error: {0}")]
Eval(#[from] EvalError),
#[error("Session error: {0}")]
Session(#[from] SessionError),
#[error("A2A error: {0}")]
A2A(#[from] A2AError),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_from_openai_error() {
let err = Error::from(OpenAIError::Http("timeout".to_string()));
assert!(matches!(err, Error::OpenAI(OpenAIError::Http(_))));
assert!(err.to_string().contains("OpenAI"));
}
#[test]
fn test_from_agent_error() {
let err = Error::from(AgentError::ToolExecutionError("tool failed".to_string()));
assert!(matches!(
err,
Error::Agent(AgentError::ToolExecutionError(_))
));
}
#[test]
fn test_from_chain_error() {
let err = Error::from(ChainError::ExecutionError("bad request".to_string()));
assert!(matches!(err, Error::Chain(ChainError::ExecutionError(_))));
}
#[test]
fn test_from_memory_error() {
let err = Error::from(MemoryError::LoadError("corrupt".to_string()));
assert!(matches!(err, Error::Memory(MemoryError::LoadError(_))));
}
#[test]
fn test_from_retriever_error() {
let err = Error::from(RetrieverError::NoResults);
assert!(matches!(err, Error::Retriever(RetrieverError::NoResults)));
}
#[test]
fn test_display_format() {
let err = Error::from(ToolError::ExecutionFailed("timeout".to_string()));
let msg = err.to_string();
assert!(msg.contains("Tool error"));
assert!(msg.contains("timeout"));
}
#[test]
fn test_source_chain() {
use std::error::Error as StdError;
let err = Error::from(EmbeddingError::HttpError("invalid".to_string()));
assert!(StdError::source(&err).is_some());
}
}