alopex_sql/storage/
error.rs

1use thiserror::Error;
2
3/// Result alias for storage operations.
4pub type Result<T> = std::result::Result<T, StorageError>;
5
6/// Storage-layer error type.
7#[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 is read-only")]
31    TransactionReadOnly,
32
33    #[error("transaction closed")]
34    TransactionClosed,
35
36    #[error("invalid key format")]
37    InvalidKeyFormat,
38
39    #[error("kv error: {0}")]
40    KvError(alopex_core::error::Error),
41}
42
43impl From<alopex_core::error::Error> for StorageError {
44    fn from(err: alopex_core::error::Error) -> Self {
45        use alopex_core::error::Error as CoreError;
46        match err {
47            CoreError::TxnConflict => StorageError::TransactionConflict,
48            CoreError::TxnReadOnly => StorageError::TransactionReadOnly,
49            CoreError::TxnClosed => StorageError::TransactionClosed,
50            other => StorageError::KvError(other),
51        }
52    }
53}