2024-10-10 14:09:31 +03:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
|
pub enum DbError {
|
|
|
|
|
#[error("RocksDb error")]
|
|
|
|
|
RocksDbError {
|
|
|
|
|
error: rocksdb::Error,
|
|
|
|
|
additional_info: Option<String>,
|
|
|
|
|
},
|
|
|
|
|
#[error("Serialization error")]
|
|
|
|
|
SerializationError {
|
2025-09-25 11:53:42 +03:00
|
|
|
error: borsh::io::Error,
|
2024-10-10 14:09:31 +03:00
|
|
|
additional_info: Option<String>,
|
|
|
|
|
},
|
|
|
|
|
#[error("Logic Error")]
|
|
|
|
|
DbInteractionError { additional_info: String },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DbError {
|
|
|
|
|
pub fn rocksdb_cast_message(rerr: rocksdb::Error, message: Option<String>) -> Self {
|
|
|
|
|
Self::RocksDbError {
|
|
|
|
|
error: rerr,
|
|
|
|
|
additional_info: message,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 11:53:42 +03:00
|
|
|
pub fn borsh_cast_message(berr: borsh::io::Error, message: Option<String>) -> Self {
|
2024-10-10 14:09:31 +03:00
|
|
|
Self::SerializationError {
|
2025-09-25 11:53:42 +03:00
|
|
|
error: berr,
|
2024-10-10 14:09:31 +03:00
|
|
|
additional_info: message,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn db_interaction_error(message: String) -> Self {
|
|
|
|
|
Self::DbInteractionError {
|
|
|
|
|
additional_info: message,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|