1use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Error, Debug)]
16pub enum Error {
17 #[error("[VELES-001] Collection '{0}' already exists")]
19 CollectionExists(String),
20
21 #[error("[VELES-002] Collection '{0}' not found")]
23 CollectionNotFound(String),
24
25 #[error("[VELES-003] Point with ID '{0}' not found")]
27 PointNotFound(u64),
28
29 #[error("[VELES-004] Vector dimension mismatch: expected {expected}, got {actual}")]
31 DimensionMismatch {
32 expected: usize,
34 actual: usize,
36 },
37
38 #[error("[VELES-005] Invalid vector: {0}")]
40 InvalidVector(String),
41
42 #[error("[VELES-006] Storage error: {0}")]
44 Storage(String),
45
46 #[error("[VELES-007] Index error: {0}")]
48 Index(String),
49
50 #[error("[VELES-008] Index corrupted: {0}")]
54 IndexCorrupted(String),
55
56 #[error("[VELES-009] Configuration error: {0}")]
58 Config(String),
59
60 #[error("[VELES-010] Query error: {0}")]
64 Query(String),
65
66 #[error("[VELES-011] IO error: {0}")]
68 Io(#[from] std::io::Error),
69
70 #[error("[VELES-012] Serialization error: {0}")]
72 Serialization(String),
73
74 #[error("[VELES-013] Internal error: {0}")]
78 Internal(String),
79
80 #[error("[VELES-014] Vector not allowed on metadata-only collection '{0}'")]
82 VectorNotAllowed(String),
83
84 #[error("[VELES-015] Vector search not supported on metadata-only collection '{0}'. Use query() instead.")]
86 SearchNotSupported(String),
87
88 #[error("[VELES-016] Vector required for collection '{0}' (not metadata-only)")]
90 VectorRequired(String),
91
92 #[error("[VELES-017] Schema validation error: {0}")]
94 SchemaValidation(String),
95
96 #[error("[VELES-018] Graph operation not supported: {0}")]
98 GraphNotSupported(String),
99
100 #[error("[VELES-019] Edge with ID '{0}' already exists")]
102 EdgeExists(u64),
103
104 #[error("[VELES-020] Edge with ID '{0}' not found")]
106 EdgeNotFound(u64),
107
108 #[error("[VELES-021] Invalid edge label: {0}")]
110 InvalidEdgeLabel(String),
111
112 #[error("[VELES-022] Node with ID '{0}' not found")]
114 NodeNotFound(u64),
115
116 #[error("[VELES-023] Numeric overflow: {0}")]
121 Overflow(String),
122
123 #[error("[VELES-024] Column store error: {0}")]
127 ColumnStoreError(String),
128
129 #[error("[VELES-025] GPU error: {0}")]
133 GpuError(String),
134
135 #[error("[VELES-026] Epoch mismatch: {0}")]
140 EpochMismatch(String),
141}
142
143impl Error {
144 #[must_use]
146 pub const fn code(&self) -> &'static str {
147 match self {
148 Self::CollectionExists(_) => "VELES-001",
149 Self::CollectionNotFound(_) => "VELES-002",
150 Self::PointNotFound(_) => "VELES-003",
151 Self::DimensionMismatch { .. } => "VELES-004",
152 Self::InvalidVector(_) => "VELES-005",
153 Self::Storage(_) => "VELES-006",
154 Self::Index(_) => "VELES-007",
155 Self::IndexCorrupted(_) => "VELES-008",
156 Self::Config(_) => "VELES-009",
157 Self::Query(_) => "VELES-010",
158 Self::Io(_) => "VELES-011",
159 Self::Serialization(_) => "VELES-012",
160 Self::Internal(_) => "VELES-013",
161 Self::VectorNotAllowed(_) => "VELES-014",
162 Self::SearchNotSupported(_) => "VELES-015",
163 Self::VectorRequired(_) => "VELES-016",
164 Self::SchemaValidation(_) => "VELES-017",
165 Self::GraphNotSupported(_) => "VELES-018",
166 Self::EdgeExists(_) => "VELES-019",
167 Self::EdgeNotFound(_) => "VELES-020",
168 Self::InvalidEdgeLabel(_) => "VELES-021",
169 Self::NodeNotFound(_) => "VELES-022",
170 Self::Overflow(_) => "VELES-023",
171 Self::ColumnStoreError(_) => "VELES-024",
172 Self::GpuError(_) => "VELES-025",
173 Self::EpochMismatch(_) => "VELES-026",
174 }
175 }
176
177 #[must_use]
181 pub const fn is_recoverable(&self) -> bool {
182 !matches!(
183 self,
184 Self::IndexCorrupted(_) | Self::Internal(_) | Self::EpochMismatch(_)
185 )
186 }
187}
188
189impl From<crate::velesql::ParseError> for Error {
191 fn from(err: crate::velesql::ParseError) -> Self {
192 Self::Query(err.to_string())
193 }
194}