Skip to main content

converge_knowledge/
error.rs

1//! Error types for the knowledge base.
2
3use thiserror::Error;
4
5/// Result type alias using the crate's Error type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur in the knowledge base.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Entry not found in the knowledge base.
12    #[error("Entry not found: {0}")]
13    NotFound(String),
14
15    /// Invalid embedding dimension.
16    #[error("Invalid embedding dimension: expected {expected}, got {actual}")]
17    DimensionMismatch { expected: usize, actual: usize },
18
19    /// Storage backend error.
20    #[error("Storage error: {0}")]
21    Storage(String),
22
23    /// Embedding generation error.
24    #[error("Embedding error: {0}")]
25    Embedding(String),
26
27    /// Learning engine error.
28    #[error("Learning error: {0}")]
29    Learning(String),
30
31    /// Serialization error.
32    #[error("Serialization error: {0}")]
33    Serialization(#[from] bincode::Error),
34
35    /// JSON serialization error.
36    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38
39    /// IO error.
40    #[error("IO error: {0}")]
41    Io(#[from] std::io::Error),
42
43    /// Invalid configuration.
44    #[error("Invalid configuration: {0}")]
45    Config(String),
46
47    /// Index corruption detected.
48    #[error("Index corruption: {0}")]
49    IndexCorruption(String),
50
51    /// Concurrent access conflict.
52    #[error("Concurrent access conflict: {0}")]
53    ConcurrencyConflict(String),
54
55    /// Ingest/parsing error.
56    #[error("Ingest error: {0}")]
57    Ingest(String),
58}
59
60impl Error {
61    /// Create a storage error.
62    pub fn storage(msg: impl Into<String>) -> Self {
63        Self::Storage(msg.into())
64    }
65
66    /// Create an embedding error.
67    pub fn embedding(msg: impl Into<String>) -> Self {
68        Self::Embedding(msg.into())
69    }
70
71    /// Create a learning error.
72    pub fn learning(msg: impl Into<String>) -> Self {
73        Self::Learning(msg.into())
74    }
75
76    /// Create a not found error.
77    pub fn not_found(id: impl Into<String>) -> Self {
78        Self::NotFound(id.into())
79    }
80
81    /// Create a config error.
82    pub fn config(msg: impl Into<String>) -> Self {
83        Self::Config(msg.into())
84    }
85
86    /// Create an ingest error.
87    pub fn ingest(msg: impl Into<String>) -> Self {
88        Self::Ingest(msg.into())
89    }
90}