use rusqlite::{Error, ErrorCode};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
#[cfg_attr(test, derive(PartialEq))]
pub enum DatabaseError {
#[error("Cannot open database")]
CannotOpen,
#[error("This file is not a database")]
NotADatabase,
#[error("Database is busy")]
DatabaseBusy,
#[error("Disk is full")]
DiskFull,
#[error("{0}")]
Other(String),
}
impl From<Error> for DatabaseError {
fn from(value: Error) -> Self {
match value {
Error::SqliteFailure(code, _) => match code.code {
ErrorCode::DiskFull => Self::DiskFull,
ErrorCode::CannotOpen => Self::CannotOpen,
ErrorCode::NotADatabase => Self::NotADatabase,
ErrorCode::DatabaseBusy => Self::DatabaseBusy,
_ => Self::Other(value.to_string()),
},
_ => Self::Other(value.to_string()),
}
}
}