alopex_sql/storage/
error.rs1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, StorageError>;
5
6#[derive(Debug, Error)]
8pub enum StorageError {
9 #[error("primary key violation: table_id={table_id}, row_id={row_id}")]
10 PrimaryKeyViolation { table_id: u32, row_id: u64 },
11
12 #[error("unique constraint violation: index_id={index_id}")]
13 UniqueViolation { index_id: u32 },
14
15 #[error("null constraint violation: column={column}")]
16 NullConstraintViolation { column: String },
17
18 #[error("corrupted data: {reason}")]
19 CorruptedData { reason: String },
20
21 #[error("type mismatch: expected {expected}, got {actual}")]
22 TypeMismatch { expected: String, actual: String },
23
24 #[error("row not found: table_id={table_id}, row_id={row_id}")]
25 RowNotFound { table_id: u32, row_id: u64 },
26
27 #[error("transaction conflict")]
28 TransactionConflict,
29
30 #[error("transaction closed")]
31 TransactionClosed,
32
33 #[error("invalid key format")]
34 InvalidKeyFormat,
35
36 #[error("kv error: {0}")]
37 KvError(alopex_core::error::Error),
38}
39
40impl From<alopex_core::error::Error> for StorageError {
41 fn from(err: alopex_core::error::Error) -> Self {
42 use alopex_core::error::Error as CoreError;
43 match err {
44 CoreError::TxnConflict => StorageError::TransactionConflict,
45 CoreError::TxnClosed => StorageError::TransactionClosed,
46 other => StorageError::KvError(other),
47 }
48 }
49}