1use std::fmt;
2
3#[derive(Debug)]
5pub enum KVStoreError {
6 DatabaseError(redb::DatabaseError),
7 TransactionError(redb::TransactionError),
8 TableError(redb::TableError),
9 CommitError(redb::CommitError),
10 SerializationError(postcard::Error),
11 StorageError(redb::StorageError),
12 Task(tokio::task::JoinError),
13}
14
15impl fmt::Display for KVStoreError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 KVStoreError::DatabaseError(e) => write!(f, "Database error: {}", e),
19 KVStoreError::TransactionError(e) => write!(f, "Transaction error: {}", e),
20 KVStoreError::TableError(e) => write!(f, "Table error: {}", e),
21 KVStoreError::CommitError(e) => write!(f, "CommitError error: {}", e),
22 KVStoreError::SerializationError(e) => write!(f, "Serialization error: {}", e),
23 KVStoreError::StorageError(e) => write!(f, "Storage error: {}", e),
24 KVStoreError::Task(e) => write!(f, "Internal task join error: {}", e),
25 }
26 }
27}
28
29impl std::error::Error for KVStoreError {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 KVStoreError::DatabaseError(e) => Some(e),
33 KVStoreError::TransactionError(e) => Some(e),
34 KVStoreError::TableError(e) => Some(e),
35 KVStoreError::CommitError(e) => Some(e),
36 KVStoreError::SerializationError(e) => Some(e),
37 KVStoreError::StorageError(e) => Some(e),
38 KVStoreError::Task(e) => Some(e),
39 }
40 }
41}
42
43impl From<redb::DatabaseError> for KVStoreError {
44 fn from(e: redb::DatabaseError) -> Self {
45 KVStoreError::DatabaseError(e)
46 }
47}
48
49impl From<redb::TransactionError> for KVStoreError {
50 fn from(e: redb::TransactionError) -> Self {
51 KVStoreError::TransactionError(e)
52 }
53}
54
55impl From<redb::TableError> for KVStoreError {
56 fn from(e: redb::TableError) -> Self {
57 KVStoreError::TableError(e)
58 }
59}
60
61impl From<redb::CommitError> for KVStoreError {
62 fn from(e: redb::CommitError) -> Self {
63 KVStoreError::CommitError(e)
64 }
65}
66
67impl From<postcard::Error> for KVStoreError {
68 fn from(e: postcard::Error) -> Self {
69 KVStoreError::SerializationError(e)
70 }
71}
72
73impl From<redb::StorageError> for KVStoreError {
74 fn from(e: redb::StorageError) -> Self {
75 KVStoreError::StorageError(e)
76 }
77}
78
79impl From<tokio::task::JoinError> for KVStoreError {
80 fn from(e: tokio::task::JoinError) -> Self {
81 KVStoreError::Task(e)
82 }
83}
84
85pub type Result<T> = std::result::Result<T, KVStoreError>;