Skip to main content

solo_core/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Workspace-wide error type.
4
5use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error)]
10pub enum Error {
11    #[error("storage error: {0}")]
12    Storage(String),
13
14    #[error("vector index error: {0}")]
15    VectorIndex(String),
16
17    #[error("embedder error: {0}")]
18    Embedder(String),
19
20    #[error("embedder protocol violation: {0}")]
21    EmbedderProtocol(&'static str),
22
23    #[error("LLM client error: {0}")]
24    Llm(String),
25
26    #[error("steward error: {0}")]
27    Steward(String),
28
29    #[error("invalid input: {0}")]
30    InvalidInput(String),
31
32    #[error("not found: {0}")]
33    NotFound(String),
34
35    #[error("conflict: {0}")]
36    Conflict(String),
37
38    #[error("io error: {0}")]
39    Io(#[from] std::io::Error),
40
41    #[error("serialization error: {0}")]
42    Serde(#[from] serde_json::Error),
43
44    #[error("uuid error: {0}")]
45    Uuid(#[from] uuid::Error),
46
47    #[error("other: {0}")]
48    Other(String),
49}
50
51impl Error {
52    pub fn storage(msg: impl Into<String>) -> Self {
53        Self::Storage(msg.into())
54    }
55    pub fn vector_index(msg: impl Into<String>) -> Self {
56        Self::VectorIndex(msg.into())
57    }
58    pub fn embedder(msg: impl Into<String>) -> Self {
59        Self::Embedder(msg.into())
60    }
61    pub fn llm(msg: impl Into<String>) -> Self {
62        Self::Llm(msg.into())
63    }
64    pub fn steward(msg: impl Into<String>) -> Self {
65        Self::Steward(msg.into())
66    }
67    pub fn invalid_input(msg: impl Into<String>) -> Self {
68        Self::InvalidInput(msg.into())
69    }
70    pub fn not_found(msg: impl Into<String>) -> Self {
71        Self::NotFound(msg.into())
72    }
73    pub fn conflict(msg: impl Into<String>) -> Self {
74        Self::Conflict(msg.into())
75    }
76}