ollama_native/
error.rs

1use serde::Deserialize;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum OllamaError {
6    /// Error occurred during HTTP request execution.
7    #[error("request error: {0}")]
8    RequestError(reqwest::Error),
9
10    /// Error occurred while decoding the response body.
11    #[error("decoding error: {0}")]
12    DecodingError(reqwest::Error),
13
14    /// Error occurred while decoding a streaming response.
15    #[cfg(feature = "stream")]
16    #[error("stream decoding error: {0}")]
17    StreamDecodingError(String),
18
19    /// The response format is invalid or unexpected.
20    #[error("invalid format: {0}")]
21    InvalidFormat(String),
22
23    /// Error returned by the Ollama server.
24    #[error("ollama error: {0}")]
25    OllamaServerError(String),
26
27    /// The requested model does not exist on the server.
28    #[cfg(feature = "model")]
29    #[error("model does not exist")]
30    ModelDoesNotExist,
31
32    /// The requested blob does not exist on the server.
33    #[cfg(feature = "model")]
34    #[error("blob does not exist")]
35    BlobDoesNotExist,
36
37    /// The digest of the blob does not match the expected value.
38    #[cfg(feature = "model")]
39    #[error("unexpected digest")]
40    UnexpectedDigest,
41
42    /// Error occurred while performing file operations.
43    #[cfg(feature = "model")]
44    #[error("file error: {0}")]
45    FileError(std::io::Error),
46}
47
48#[derive(Debug, Deserialize)]
49pub struct OllamaServerError {
50    pub error: String,
51}