anchor_chain/
error.rs

1//! Defines error types for Anchor Chain.
2
3use async_openai::error::OpenAIError;
4use aws_sdk_bedrockruntime::error::SdkError;
5use aws_sdk_bedrockruntime::operation::invoke_model::InvokeModelError;
6
7/// Defines errors types for Anchor Chain
8#[derive(Debug, thiserror::Error)]
9pub enum AnchorChainError {
10    /// Occurs when failing to construct OpenAI prompts, messages or when invoking
11    /// the model fails.
12    #[error("OpenAI error: {0}")]
13    OpenAIError(#[from] OpenAIError),
14
15    /// Occurs when failing to construct or invoke a model in Bedrock.
16    #[error("Bedrock error: {0}")]
17    BedrockError(#[from] SdkError<InvokeModelError>),
18
19    /// Error constructing or rendering Tera templates.
20    #[error("error constructing or rendering Tera template: {0}")]
21    TeraTemplateError(#[from] tera::Error),
22
23    /// Error when no response is returned from the LLM model.
24    #[error("no response returned from the model")]
25    EmptyResponseError,
26
27    /// Generic error that occurs when serializing or deserializing a request.
28    #[error("error processing request: {0}")]
29    RequestError(#[from] serde_json::Error),
30
31    /// Error when configuring or using OpenSearch.
32    #[error("OpenSearch error: {0}")]
33    OpenSearchError(#[from] opensearch::Error),
34
35    /// Error that occurs when calling OpenSearch APIs.
36    #[error("OpenSearch returned error: {0}")]
37    OpenSearchInternalError(String),
38
39    #[error("Error parsing input: {0}")]
40    ParseError(String),
41
42    #[error("invalid input: {0}")]
43    InvalidInputError(String),
44
45    /// Generic error calling a model.
46    #[error("error processing model response: {0}")]
47    ModelError(String),
48
49    // Reqwest error
50    #[error("reqwest error: {0}")]
51    ReqwestError(#[from] reqwest::Error),
52}