Skip to main content

mnemo_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5    #[error("not found: {0}")]
6    NotFound(String),
7
8    #[error("validation error: {0}")]
9    Validation(String),
10
11    #[error("permission denied: {0}")]
12    PermissionDenied(String),
13
14    #[error("storage error: {0}")]
15    Storage(String),
16
17    #[error("storage error: {message}")]
18    StorageSource {
19        message: String,
20        #[source]
21        source: Box<dyn std::error::Error + Send + Sync>,
22    },
23
24    #[error("index error: {0}")]
25    Index(String),
26
27    /// A storage/index backend does not implement a requested capability.
28    /// Returned (not silently empty) when a caller asks a backend to do
29    /// something it cannot — e.g. semantic/vector recall on the PostgreSQL
30    /// backend, whose pgvector ANN search is not wired. `detail` carries the
31    /// actionable guidance (which backend to use + a tracking link).
32    #[error("backend '{backend}' does not support capability '{capability}': {detail}")]
33    BackendUnsupported {
34        backend: String,
35        capability: String,
36        detail: String,
37    },
38
39    #[error("index error: {message}")]
40    IndexSource {
41        message: String,
42        #[source]
43        source: Box<dyn std::error::Error + Send + Sync>,
44    },
45
46    #[error("embedding error: {0}")]
47    Embedding(String),
48
49    #[error("embedding error: {message}")]
50    EmbeddingSource {
51        message: String,
52        #[source]
53        source: Box<dyn std::error::Error + Send + Sync>,
54    },
55
56    #[error("internal error: {0}")]
57    Internal(String),
58}
59
60impl From<duckdb::Error> for Error {
61    fn from(e: duckdb::Error) -> Self {
62        Error::Storage(e.to_string())
63    }
64}
65
66impl From<serde_json::Error> for Error {
67    fn from(e: serde_json::Error) -> Self {
68        Error::Internal(e.to_string())
69    }
70}
71
72impl From<reqwest::Error> for Error {
73    fn from(e: reqwest::Error) -> Self {
74        Error::Embedding(e.to_string())
75    }
76}
77
78pub type Result<T> = std::result::Result<T, Error>;