Skip to main content

xz_knowledge_graph/
error.rs

1/// Knowledge graph errors.
2#[derive(Debug, thiserror::Error)]
3pub enum KgError {
4    #[error("Database error: {0}")]
5    Database(String),
6
7    #[error("Entity not found: {0}")]
8    EntityNotFound(String),
9
10    #[error("Relation not found: {0}")]
11    RelationNotFound(String),
12
13    #[error("Entity exists and update not allowed: {0}")]
14    EntityExists(String),
15
16    #[error("Import conflict: {0}")]
17    ImportConflict(String),
18
19    #[error("Path not found: {from} -> {to}")]
20    PathNotFound { from: String, to: String },
21
22    #[error("Max depth exceeded: {depth} > {max}")]
23    MaxDepthExceeded { depth: u32, max: u32 },
24
25    #[error("Circular reference detected: entity={0}")]
26    CircularReference(String),
27
28    #[error("Validation error: {0}")]
29    Validation(String),
30
31    #[error("Transaction failed: {0}")]
32    Transaction(String),
33
34    #[error("Serialization error: {0}")]
35    Serialization(String),
36}
37
38impl KgError {
39    pub fn is_retryable(&self) -> bool {
40        matches!(self, KgError::Database(_) | KgError::Transaction(_))
41    }
42}