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(#[from] LlmError),
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    /// A tool invoked by an agent returned an error.
16    #[error("tool error: {0}")]
17    ToolError(#[from] ToolError),
18    /// Output could not be parsed into the expected type.
19    #[error("parse error: {0}")]
20    ParseError(String),
21    /// Any error not covered by the variants above.
22    #[error("{0}")]
23    Other(String),
24}
25
26/// Errors produced by an [`Llm`](crate::Llm) during generation.
27#[derive(Debug, Error, Clone)]
28pub enum LlmError {
29    /// HTTP or network-level failure contacting the provider.
30    #[error("request failed: {0}")]
31    RequestFailed(String),
32    /// The provider rejected the request (auth, quota, rate limit, …).
33    #[error("provider error: {0}")]
34    ProviderError(String),
35    /// The model returned a response that could not be decoded.
36    #[error("invalid response: {0}")]
37    InvalidResponse(String),
38    /// Function/tool calling is not supported by this provider.
39    #[error("tool use not supported: {0}")]
40    ToolUseNotSupported(String),
41    /// Any error not covered by the variants above.
42    #[error("{0}")]
43    Other(String),
44}
45
46/// Errors produced by a [`Tool`](crate::Tool) during execution.
47#[derive(Debug, Error, Clone)]
48pub enum ToolError {
49    /// The input provided to the tool was invalid or could not be parsed.
50    #[error("invalid input: {0}")]
51    InvalidInput(String),
52    /// The tool's operation failed at runtime.
53    #[error("execution failed: {0}")]
54    ExecutionFailed(String),
55    /// Any error not covered by the variants above.
56    #[error("{0}")]
57    Other(String),
58}