Skip to main content

astraea_core/
error.rs

1use crate::types::{EdgeId, NodeId, PageId};
2
3/// Top-level error type for AstraeaDB.
4#[derive(Debug, thiserror::Error)]
5pub enum AstraeaError {
6    // --- Storage errors ---
7    #[error("page {0} not found")]
8    PageNotFound(PageId),
9
10    #[error("page {0} is corrupted: {1}")]
11    PageCorrupted(PageId, String),
12
13    #[error("buffer pool is full, cannot pin page {0}")]
14    BufferPoolFull(PageId),
15
16    #[error("storage I/O error: {0}")]
17    StorageIo(#[from] std::io::Error),
18
19    #[error("storage error: {0}")]
20    Storage(String),
21
22    // --- Graph errors ---
23    #[error("node {0} not found")]
24    NodeNotFound(NodeId),
25
26    #[error("edge {0} not found")]
27    EdgeNotFound(EdgeId),
28
29    #[error("duplicate node {0}")]
30    DuplicateNode(NodeId),
31
32    #[error("duplicate edge {0}")]
33    DuplicateEdge(EdgeId),
34
35    // --- Transaction errors ---
36    #[error("transaction aborted: write-write conflict on entity {0}")]
37    WriteConflict(u64),
38
39    #[error("transaction not active")]
40    TransactionNotActive,
41
42    // --- Query errors ---
43    #[error("parse error at position {position}: {message}")]
44    ParseError { position: usize, message: String },
45
46    #[error("query execution error: {0}")]
47    QueryExecution(String),
48
49    #[error("unknown label: {0}")]
50    UnknownLabel(String),
51
52    #[error("unknown edge type: {0}")]
53    UnknownEdgeType(String),
54
55    // --- Vector errors ---
56    #[error("embedding dimension mismatch: expected {expected}, got {got}")]
57    DimensionMismatch { expected: usize, got: usize },
58
59    #[error("node {0} has no embedding")]
60    NoEmbedding(NodeId),
61
62    #[error("vector index not built")]
63    IndexNotBuilt,
64
65    // --- Serialization errors ---
66    #[error("serialization error: {0}")]
67    Serialization(String),
68
69    #[error("deserialization error: {0}")]
70    Deserialization(String),
71
72    // --- Configuration errors ---
73    #[error("configuration error: {0}")]
74    Config(String),
75
76    // --- Authentication errors ---
77    #[error("authentication required")]
78    AuthenticationRequired,
79
80    #[error("invalid credentials")]
81    InvalidCredentials,
82
83    #[error("access denied: {0}")]
84    AccessDenied(String),
85
86    // --- TLS errors ---
87    #[error("TLS error: {0}")]
88    Tls(String),
89}
90
91/// Convenience alias.
92pub type Result<T> = std::result::Result<T, AstraeaError>;