use thiserror::Error;
#[derive(Debug, Error)]
pub enum CsafError {
#[error("Storage error: {0}")]
Storage(String),
#[error("Database error: {0}")]
Database(#[from] rusqlite::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Validation failed: {0}")]
Validation(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Configuration error: {0}")]
Config(String),
#[error("Document not found: {0}")]
NotFound(String),
#[error("Document already exists: {0}")]
Duplicate(String),
#[error("Import error: {0}")]
Import(String),
#[error("Export error: {0}")]
Export(String),
}
impl From<redb::Error> for CsafError {
fn from(e: redb::Error) -> Self {
Self::Storage(e.to_string())
}
}
impl From<redb::DatabaseError> for CsafError {
fn from(e: redb::DatabaseError) -> Self {
Self::Storage(e.to_string())
}
}
impl From<redb::TableError> for CsafError {
fn from(e: redb::TableError) -> Self {
Self::Storage(e.to_string())
}
}
impl From<redb::TransactionError> for CsafError {
fn from(e: redb::TransactionError) -> Self {
Self::Storage(e.to_string())
}
}
impl From<redb::CommitError> for CsafError {
fn from(e: redb::CommitError) -> Self {
Self::Storage(e.to_string())
}
}
impl From<redb::StorageError> for CsafError {
fn from(e: redb::StorageError) -> Self {
Self::Storage(e.to_string())
}
}
pub type Result<T> = std::result::Result<T, CsafError>;