#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("wrong key or not a {what} database ({detail})")]
WrongKey { what: String, detail: String },
#[error("existing database is not a plaintext SQLite file")]
NotPlaintext,
#[error("database is not encrypted; rekey cannot encrypt it (convert it first)")]
NotEncrypted,
#[error("rekey did not take effect; the database keeps its old key")]
RekeyFailed,
#[error("this SQLite has no encryption (SQLCipher); refusing to apply a key")]
NoCipher,
#[error("invalid {what}: {msg}")]
Invalid { what: &'static str, msg: String },
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Sqlite(#[from] rusqlite::Error),
#[cfg(feature = "sync")]
#[error(transparent)]
Json(#[from] serde_json::Error),
}
impl StorageError {
pub fn invalid(what: &'static str, msg: impl Into<String>) -> Self {
StorageError::Invalid { what, msg: msg.into() }
}
}
pub type Result<T> = std::result::Result<T, StorageError>;