1use serde::Deserialize;
2use static_assertions::assert_impl_all;
3use thiserror::Error;
4
5assert_impl_all!(OllamaError: Send, Sync);
6pub type Result<T> = std::result::Result<T, OllamaError>;
11
12#[derive(Error, Debug)]
17pub enum OllamaError {
18 #[error("Error calling tool")]
19 ToolCallError(#[from] ToolCallError),
20 #[error("Ollama JSON error")]
21 JsonError(#[from] serde_json::Error),
22 #[error("Reqwest error")]
23 ReqwestError(#[from] reqwest::Error),
24 #[error("Internal Ollama error: {}", .0.message)]
25 InternalError(InternalOllamaError),
26 #[error("{0}")]
27 Other(String),
28}
29
30#[derive(Deserialize, Debug)]
34pub struct InternalOllamaError {
35 #[serde(rename = "error")]
36 pub message: String,
37}
38
39#[derive(Error, Debug)]
44pub enum ToolCallError {
45 #[error("Ollama attempted to call a tool with a name we do not recognize")]
46 UnknownToolName,
47 #[error(
48 "Could not convert tool arguments from Ollama into what the tool expected, or vice versa"
49 )]
50 InvalidToolArguments(#[from] serde_json::Error),
51 #[error("Tool errored internally when it was called")]
52 InternalToolError(#[from] Box<dyn std::error::Error + Send + Sync>),
53}