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 /// On-disk segment is corrupted (e.g., checksum failure).
42 #[error("corrupted segment: {reason}")]
43 CorruptedSegment {
44 /// Reason for corruption detection.
45 reason: String,
46 },
47
48 /// A vector with an unexpected dimension was provided.
49 #[error("dimension mismatch: expected {expected}, got {actual}")]
50 DimensionMismatch {
51 /// Expected dimension.
52 expected: usize,
53 /// Dimension of the provided vector.
54 actual: usize,
55 },
56
57 /// A metric that is not supported was requested.
58 #[error("unsupported metric: {metric}")]
59 UnsupportedMetric {
60 /// Name of the unsupported metric.
61 metric: String,
62 },
63
64 /// A vector value is invalid for the requested operation.
65 #[error("invalid vector at index {index}: {reason}")]
66 InvalidVector {
67 /// Zero-based index of the offending vector.
68 index: usize,
69 /// Reason for invalidation.
70 reason: String,
71 },
72
73 /// A filter expression is malformed or unsupported.
74 #[error("invalid filter: {0}")]
75 InvalidFilter(String),
76
77 /// Memory usage exceeded configured limit.
78 #[error("memory limit exceeded: limit={limit}, requested={requested}")]
79 MemoryLimitExceeded {
80 /// Maximum allowed memory (bytes).
81 limit: usize,
82 /// Requested memory (bytes) that triggered the limit.
83 requested: usize,
84 },
85
86 /// The provided path already exists and cannot be overwritten.
87 #[error("path exists: {0}")]
88 PathExists(PathBuf),
89
90 /// An index configuration parameter is invalid.
91 #[error("invalid parameter {param}: {reason}")]
92 InvalidParameter {
93 /// Name of the invalid parameter.
94 param: String,
95 /// Description of the expected range or constraint.
96 reason: String,
97 },
98
99 /// An index with the requested name was not found.
100 #[error("index not found: {name}")]
101 IndexNotFound {
102 /// Name of the missing index.
103 name: String,
104 },
105
106 /// An index failed integrity checks.
107 #[error("corrupted index {name}: {reason}")]
108 CorruptedIndex {
109 /// Name of the corrupted index.
110 name: String,
111 /// Description of the corruption.
112 reason: String,
113 },
114
115 /// The stored index version is unsupported by this binary.
116 #[error("unsupported index version: found {found}, supported {supported}")]
117 UnsupportedIndexVersion {
118 /// Version detected in storage.
119 found: u32,
120 /// Highest supported version.
121 supported: u32,
122 },
123
124 /// An unknown configuration or runtime option was provided.
125 #[error("unknown option: {key}")]
126 UnknownOption {
127 /// Name of the option.
128 key: String,
129 },
130
131 /// A column type does not match the expected layout.
132 #[error("invalid column type for {column}, expected {expected}")]
133 InvalidColumnType {
134 /// Column name.
135 column: String,
136 /// Expected type description.
137 expected: String,
138 },
139
140 /// The index is busy and cannot serve the requested operation.
141 #[error("index busy during {operation}")]
142 IndexBusy {
143 /// Operation that was attempted.
144 operation: String,
145 },
146
147 /// Errors originating from columnar components.
148 #[error("columnar error: {0}")]
149 Columnar(#[from] ColumnarError),
150
151 /// An S3 operation failed.
152 #[error("S3 error: {0}")]
153 S3(String),
154
155 /// Required credentials are missing.
156 #[error("missing credentials: {0}")]
157 MissingCredentials(String),
158}