Skip to main content

codemem_core/
error.rs

1/// Unified error type for Codemem.
2///
3/// Variants like `Storage(String)` intentionally carry a stringified error
4/// message rather than the original typed error. This avoids coupling
5/// `codemem-core` to storage-specific dependencies (e.g. `rusqlite`),
6/// keeping the core crate lightweight and backend-agnostic.
7#[derive(Debug, thiserror::Error)]
8pub enum CodememError {
9    #[error("Storage error: {0}")]
10    Storage(String),
11
12    #[error("Vector error: {0}")]
13    Vector(String),
14
15    #[error("Embedding error: {0}")]
16    Embedding(String),
17
18    #[error("Hook error: {0}")]
19    Hook(String),
20
21    #[error("Invalid memory type: {0}")]
22    InvalidMemoryType(String),
23
24    #[error("Invalid relationship type: {0}")]
25    InvalidRelationshipType(String),
26
27    #[error("Invalid node kind: {0}")]
28    InvalidNodeKind(String),
29
30    #[error("Not found: {0}")]
31    NotFound(String),
32
33    #[error("Invalid input: {0}")]
34    InvalidInput(String),
35
36    #[error("Duplicate content (hash: {0})")]
37    Duplicate(String),
38
39    #[error("Internal error: {0}")]
40    Internal(String),
41
42    #[error("Configuration error: {0}")]
43    Config(String),
44
45    #[error("Lock poisoned: {0}")]
46    LockPoisoned(String),
47
48    #[error("IO error: {0}")]
49    Io(#[from] std::io::Error),
50
51    #[error("JSON error: {0}")]
52    Json(#[from] serde_json::Error),
53}
54
55impl From<toml::de::Error> for CodememError {
56    fn from(e: toml::de::Error) -> Self {
57        CodememError::Config(e.to_string())
58    }
59}
60
61#[cfg(test)]
62#[path = "tests/error_tests.rs"]
63mod tests;