weirdnet_storage/
error.rs1#[derive(Debug, thiserror::Error)]
4pub enum StorageError {
5 #[error("wrong key or not a {what} database ({detail})")]
7 WrongKey { what: String, detail: String },
8 #[error("existing database is not a plaintext SQLite file")]
10 NotPlaintext,
11 #[error("database is not encrypted; rekey cannot encrypt it (convert it first)")]
13 NotEncrypted,
14 #[error("rekey did not take effect; the database keeps its old key")]
17 RekeyFailed,
18 #[error("this SQLite has no encryption (SQLCipher); refusing to apply a key")]
20 NoCipher,
21 #[error("invalid {what}: {msg}")]
22 Invalid { what: &'static str, msg: String },
23 #[error(transparent)]
24 Io(#[from] std::io::Error),
25 #[error(transparent)]
26 Sqlite(#[from] rusqlite::Error),
27 #[cfg(feature = "sync")]
28 #[error(transparent)]
29 Json(#[from] serde_json::Error),
30}
31
32impl StorageError {
33 pub fn invalid(what: &'static str, msg: impl Into<String>) -> Self {
34 StorageError::Invalid { what, msg: msg.into() }
35 }
36}
37
38pub type Result<T> = std::result::Result<T, StorageError>;