1use 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("forbidden: {0}")]
44 Forbidden(String),
45
46 #[error("io error: {0}")]
47 Io(#[from] std::io::Error),
48
49 #[error("serialization error: {0}")]
50 Serde(#[from] serde_json::Error),
51
52 #[error("uuid error: {0}")]
53 Uuid(#[from] uuid::Error),
54
55 #[error("other: {0}")]
56 Other(String),
57}
58
59impl Error {
60 pub fn storage(msg: impl Into<String>) -> Self {
61 Self::Storage(msg.into())
62 }
63 pub fn vector_index(msg: impl Into<String>) -> Self {
64 Self::VectorIndex(msg.into())
65 }
66 pub fn embedder(msg: impl Into<String>) -> Self {
67 Self::Embedder(msg.into())
68 }
69 pub fn llm(msg: impl Into<String>) -> Self {
70 Self::Llm(msg.into())
71 }
72 pub fn steward(msg: impl Into<String>) -> Self {
73 Self::Steward(msg.into())
74 }
75 pub fn invalid_input(msg: impl Into<String>) -> Self {
76 Self::InvalidInput(msg.into())
77 }
78 pub fn not_found(msg: impl Into<String>) -> Self {
79 Self::NotFound(msg.into())
80 }
81 pub fn conflict(msg: impl Into<String>) -> Self {
82 Self::Conflict(msg.into())
83 }
84 pub fn forbidden(msg: impl Into<String>) -> Self {
86 Self::Forbidden(msg.into())
87 }
88}