converge_knowledge/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Entry not found: {0}")]
13 NotFound(String),
14
15 #[error("Invalid embedding dimension: expected {expected}, got {actual}")]
17 DimensionMismatch {
18 expected: usize,
20 actual: usize,
22 },
23
24 #[error("Storage error: {0}")]
26 Storage(String),
27
28 #[error("Embedding error: {0}")]
30 Embedding(String),
31
32 #[error("Learning error: {0}")]
34 Learning(String),
35
36 #[error("Serialization error: {0}")]
38 Serialization(#[from] bincode::Error),
39
40 #[error("JSON error: {0}")]
42 Json(#[from] serde_json::Error),
43
44 #[error("IO error: {0}")]
46 Io(#[from] std::io::Error),
47
48 #[error("Invalid configuration: {0}")]
50 Config(String),
51
52 #[error("Index corruption: {0}")]
54 IndexCorruption(String),
55
56 #[error("Concurrent access conflict: {0}")]
58 ConcurrencyConflict(String),
59
60 #[error("Ingest error: {0}")]
62 Ingest(String),
63}
64
65impl Error {
66 pub fn storage(msg: impl Into<String>) -> Self {
68 Self::Storage(msg.into())
69 }
70
71 pub fn embedding(msg: impl Into<String>) -> Self {
73 Self::Embedding(msg.into())
74 }
75
76 pub fn learning(msg: impl Into<String>) -> Self {
78 Self::Learning(msg.into())
79 }
80
81 pub fn not_found(id: impl Into<String>) -> Self {
83 Self::NotFound(id.into())
84 }
85
86 pub fn config(msg: impl Into<String>) -> Self {
88 Self::Config(msg.into())
89 }
90
91 pub fn ingest(msg: impl Into<String>) -> Self {
93 Self::Ingest(msg.into())
94 }
95}