use thiserror::Error;
#[derive(Debug, Error)]
pub enum PersistError {
#[error("storage error: {0}")]
Storage(String),
#[error("serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("checkpoint not found: {0}")]
NotFound(uuid::Uuid),
#[error("database error: {0}")]
Database(String),
#[error("binary serialization error: {0}")]
BinarySerialization(String),
#[error("redis error: {0}")]
Redis(String),
}
impl From<rmp_serde::encode::Error> for PersistError {
fn from(err: rmp_serde::encode::Error) -> Self {
Self::BinarySerialization(err.to_string())
}
}
impl From<rmp_serde::decode::Error> for PersistError {
fn from(err: rmp_serde::decode::Error) -> Self {
Self::BinarySerialization(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::Error> for PersistError {
fn from(err: redb::Error) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::DatabaseError> for PersistError {
fn from(err: redb::DatabaseError) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::StorageError> for PersistError {
fn from(err: redb::StorageError) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::TableError> for PersistError {
fn from(err: redb::TableError) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::TransactionError> for PersistError {
fn from(err: redb::TransactionError) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "redb")]
impl From<redb::CommitError> for PersistError {
fn from(err: redb::CommitError) -> Self {
Self::Database(err.to_string())
}
}
#[cfg(feature = "valkey")]
impl From<redis::RedisError> for PersistError {
fn from(err: redis::RedisError) -> Self {
Self::Redis(err.to_string())
}
}