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 { expected: usize, actual: usize },
18
19 #[error("Storage error: {0}")]
21 Storage(String),
22
23 #[error("Embedding error: {0}")]
25 Embedding(String),
26
27 #[error("Learning error: {0}")]
29 Learning(String),
30
31 #[error("Serialization error: {0}")]
33 Serialization(#[from] bincode::Error),
34
35 #[error("JSON error: {0}")]
37 Json(#[from] serde_json::Error),
38
39 #[error("IO error: {0}")]
41 Io(#[from] std::io::Error),
42
43 #[error("Invalid configuration: {0}")]
45 Config(String),
46
47 #[error("Index corruption: {0}")]
49 IndexCorruption(String),
50
51 #[error("Concurrent access conflict: {0}")]
53 ConcurrencyConflict(String),
54
55 #[error("Ingest error: {0}")]
57 Ingest(String),
58}
59
60impl Error {
61 pub fn storage(msg: impl Into<String>) -> Self {
63 Self::Storage(msg.into())
64 }
65
66 pub fn embedding(msg: impl Into<String>) -> Self {
68 Self::Embedding(msg.into())
69 }
70
71 pub fn learning(msg: impl Into<String>) -> Self {
73 Self::Learning(msg.into())
74 }
75
76 pub fn not_found(id: impl Into<String>) -> Self {
78 Self::NotFound(id.into())
79 }
80
81 pub fn config(msg: impl Into<String>) -> Self {
83 Self::Config(msg.into())
84 }
85
86 pub fn ingest(msg: impl Into<String>) -> Self {
88 Self::Ingest(msg.into())
89 }
90}