use std::fmt;
#[derive(Debug)]
pub enum SpatioError {
DatabaseClosed,
LockError,
SerializationError,
SerializationErrorWithContext(String),
RewriteInProgress,
InvalidTimestamp,
UnexpectedEof,
InvalidFormat,
InvalidInput(String),
NotSupported(String),
ObjectNotFound,
Io(std::io::Error),
Other(String),
}
impl fmt::Display for SpatioError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
SpatioError::DatabaseClosed => write!(f, "Database is closed"),
SpatioError::LockError => write!(f, "Failed to acquire lock"),
SpatioError::SerializationError => write!(f, "Serialization error"),
SpatioError::SerializationErrorWithContext(context) => {
write!(f, "Serialization error: {}", context)
}
SpatioError::RewriteInProgress => write!(f, "Rewrite operation is already in progress"),
SpatioError::InvalidTimestamp => write!(f, "Invalid timestamp value"),
SpatioError::UnexpectedEof => write!(f, "Unexpected end of file"),
SpatioError::InvalidFormat => write!(f, "Invalid data format"),
SpatioError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
SpatioError::NotSupported(msg) => write!(f, "Not supported: {}", msg),
SpatioError::ObjectNotFound => write!(f, "Object not found"),
SpatioError::Io(err) => write!(f, "I/O error: {}", err),
SpatioError::Other(msg) => write!(f, "{}", msg),
}
}
}
impl std::error::Error for SpatioError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
SpatioError::Io(err) => Some(err),
_ => None,
}
}
}
impl From<std::io::Error> for SpatioError {
fn from(err: std::io::Error) -> Self {
SpatioError::Io(err)
}
}
pub type Result<T> = std::result::Result<T, SpatioError>;