Skip to main content

rune_chain_core/
error.rs

1use thiserror::Error;
2
3/// Errors produced by a [`Chain`](crate::Chain) during execution.
4#[derive(Debug, Error)]
5pub enum ChainError {
6    /// The underlying LLM returned an error.
7    #[error("LLM error: {0}")]
8    LlmError(String),
9    /// A required prompt variable was missing from the input map.
10    #[error("missing prompt variable: {0}")]
11    MissingVariable(String),
12    /// The chain's memory layer failed.
13    #[error("memory error: {0}")]
14    MemoryError(String),
15    /// Any error not covered by the variants above.
16    #[error("{0}")]
17    Other(String),
18}
19
20/// Errors produced by an [`Llm`](crate::Llm) during generation.
21#[derive(Debug, Error)]
22pub enum LlmError {
23    /// HTTP or network-level failure contacting the provider.
24    #[error("request failed: {0}")]
25    RequestFailed(String),
26    /// The provider rejected the request (auth, quota, rate limit, …).
27    #[error("provider error: {0}")]
28    ProviderError(String),
29    /// The model returned a response that could not be decoded.
30    #[error("invalid response: {0}")]
31    InvalidResponse(String),
32    /// Any error not covered by the variants above.
33    #[error("{0}")]
34    Other(String),
35}
36
37impl From<LlmError> for ChainError {
38    fn from(err: LlmError) -> Self {
39        ChainError::LlmError(err.to_string())
40    }
41}