alopex_core/error.rs
1//! Error and Result types for AlopexDB.
2use std::path::PathBuf;
3use thiserror::Error;
4
5use crate::columnar::error::ColumnarError;
6
7/// A convenience `Result` type.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// The error type for AlopexDB operations.
11#[derive(Debug, Error)]
12pub enum Error {
13 /// The requested key was not found.
14 #[error("key not found")]
15 NotFound,
16
17 /// The transaction has already been closed (committed or rolled back).
18 #[error("transaction is closed")]
19 TxnClosed,
20
21 /// Read-only トランザクションで書き込み操作を試みた。
22 #[error("transaction is read-only")]
23 TxnReadOnly,
24
25 /// A transaction conflict occurred (e.g., optimistic concurrency control failure).
26 #[error("transaction conflict")]
27 TxnConflict,
28
29 /// An underlying I/O error occurred.
30 #[error("io error: {0}")]
31 Io(#[from] std::io::Error),
32
33 /// The on-disk format is invalid or corrupted.
34 #[error("invalid format: {0}")]
35 InvalidFormat(String),
36
37 /// A checksum validation failed.
38 #[error("checksum mismatch")]
39 ChecksumMismatch,
40
41 /// WAL recovery stopped before completion.
42 #[error("recovery incomplete: recovered={recovered_entries}, stop_offset={stop_offset}, reason={reason}")]
43 RecoveryIncomplete {
44 /// Number of entries recovered before stopping.
45 recovered_entries: usize,
46 /// Byte offset where recovery stopped.
47 stop_offset: u64,
48 /// Reason for stopping.
49 reason: String,
50 },
51
52 /// On-disk segment is corrupted (e.g., checksum failure).
53 #[error("corrupted segment {segment_id}: {reason}")]
54 CorruptedSegment {
55 /// Segment identifier.
56 segment_id: u64,
57 /// Reason for corruption detection.
58 reason: String,
59 },
60
61 /// A vector with an unexpected dimension was provided.
62 #[error("dimension mismatch: expected {expected}, got {actual}")]
63 DimensionMismatch {
64 /// Expected dimension.
65 expected: usize,
66 /// Dimension of the provided vector.
67 actual: usize,
68 },
69
70 /// A metric that is not supported was requested.
71 #[error("unsupported metric: {metric}")]
72 UnsupportedMetric {
73 /// Name of the unsupported metric.
74 metric: String,
75 },
76
77 /// A vector value is invalid for the requested operation.
78 #[error("invalid vector at index {index}: {reason}")]
79 InvalidVector {
80 /// Zero-based index of the offending vector.
81 index: usize,
82 /// Reason for invalidation.
83 reason: String,
84 },
85
86 /// A filter expression is malformed or unsupported.
87 #[error("invalid filter: {0}")]
88 InvalidFilter(String),
89
90 /// Memory usage exceeded configured limit.
91 #[error("memory limit exceeded: limit={limit}, requested={requested}")]
92 MemoryLimitExceeded {
93 /// Maximum allowed memory (bytes).
94 limit: usize,
95 /// Requested memory (bytes) that triggered the limit.
96 requested: usize,
97 },
98
99 /// External spill operation failed.
100 #[error("spill failed: {reason}")]
101 SpillFailed {
102 /// Stable failure description.
103 reason: String,
104 },
105
106 /// A DataFrame scalar cast failed.
107 #[error("cast failed: from={from_type}, to={to_type}, reason={reason}")]
108 CastFailed {
109 /// Source type name.
110 from_type: String,
111 /// Target type name.
112 to_type: String,
113 /// Stable failure code.
114 reason: String,
115 },
116
117 /// The provided path already exists and cannot be overwritten.
118 #[error("path exists: {0}")]
119 PathExists(PathBuf),
120
121 /// An index configuration parameter is invalid.
122 #[error("invalid parameter {param}: {reason}")]
123 InvalidParameter {
124 /// Name of the invalid parameter.
125 param: String,
126 /// Description of the expected range or constraint.
127 reason: String,
128 },
129
130 /// An index with the requested name was not found.
131 #[error("index not found: {name}")]
132 IndexNotFound {
133 /// Name of the missing index.
134 name: String,
135 },
136
137 /// An index failed integrity checks.
138 #[error("corrupted index {name}: {reason}")]
139 CorruptedIndex {
140 /// Name of the corrupted index.
141 name: String,
142 /// Description of the corruption.
143 reason: String,
144 },
145
146 /// The stored index version is unsupported by this binary.
147 #[error("unsupported index version: found {found}, supported {supported}")]
148 UnsupportedIndexVersion {
149 /// Version detected in storage.
150 found: u32,
151 /// Highest supported version.
152 supported: u32,
153 },
154
155 /// An unknown configuration or runtime option was provided.
156 #[error("unknown option: {key}")]
157 UnknownOption {
158 /// Name of the option.
159 key: String,
160 },
161
162 /// A column type does not match the expected layout.
163 #[error("invalid column type for {column}, expected {expected}")]
164 InvalidColumnType {
165 /// Column name.
166 column: String,
167 /// Expected type description.
168 expected: String,
169 },
170
171 /// The index is busy and cannot serve the requested operation.
172 #[error("index busy during {operation}")]
173 IndexBusy {
174 /// Operation that was attempted.
175 operation: String,
176 },
177
178 /// Errors originating from columnar components.
179 #[error("columnar error: {0}")]
180 Columnar(#[from] ColumnarError),
181
182 /// An S3 operation failed.
183 #[error("S3 error: {0}")]
184 S3(String),
185
186 /// Required credentials are missing.
187 #[error("missing credentials: {0}")]
188 MissingCredentials(String),
189}