use std::fmt;
pub type SdkResult<T> = std::result::Result<T, SdkError>;
#[derive(Debug)]
pub enum SdkError {
DatabaseNotFound(String),
DatabaseAlreadyExists(String),
TableNotFound(String),
TableAlreadyExists(String),
DocumentNotFound(String),
InvalidQuery(String),
IoError(std::io::Error),
SerializationError(String),
ConstraintViolation(String),
TransactionError(String),
DatabaseClosed,
SecurityError(String),
BackupError(String),
Internal(String),
}
impl fmt::Display for SdkError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SdkError::DatabaseNotFound(p) => write!(f, "Database not found: {}", p),
SdkError::DatabaseAlreadyExists(p) => write!(f, "Database already exists: {}", p),
SdkError::TableNotFound(t) => write!(f, "Table not found: {}", t),
SdkError::TableAlreadyExists(t) => write!(f, "Table already exists: {}", t),
SdkError::DocumentNotFound(id) => write!(f, "Document not found: {}", id),
SdkError::InvalidQuery(q) => write!(f, "Invalid query: {}", q),
SdkError::IoError(e) => write!(f, "I/O error: {}", e),
SdkError::SerializationError(e) => write!(f, "Serialization error: {}", e),
SdkError::ConstraintViolation(c) => write!(f, "Constraint violation: {}", c),
SdkError::TransactionError(e) => write!(f, "Transaction error: {}", e),
SdkError::DatabaseClosed => write!(f, "Database is closed"),
SdkError::SecurityError(e) => write!(f, "Security error: {}", e),
SdkError::BackupError(e) => write!(f, "Backup error: {}", e),
SdkError::Internal(e) => write!(f, "Internal error: {}", e),
}
}
}
impl std::error::Error for SdkError {}
impl From<std::io::Error> for SdkError {
fn from(e: std::io::Error) -> Self {
SdkError::IoError(e)
}
}
impl From<String> for SdkError {
fn from(e: String) -> Self {
SdkError::Internal(e)
}
}
impl From<serde_json::Error> for SdkError {
fn from(e: serde_json::Error) -> Self {
SdkError::SerializationError(e.to_string())
}
}