use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("wrong password or not a vault file")]
WrongPasswordOrNotAVault,
#[error("file is too small to be a vault")]
TooSmall,
#[error("unsupported vault format version {0}; upgrade sefy")]
UnsupportedFormat(u8),
#[error("vault already exists: {0}")]
AlreadyExists(PathBuf),
#[error("no item with id {0}")]
ItemNotFound(i64),
#[error("nothing matches {0:?}")]
NotFound(String),
#[error("{} items match {reference:?}", candidates.len())]
Ambiguous {
reference: String,
candidates: Vec<crate::model::ItemSummary>,
},
#[error("item {id} is a {actual}, not a {expected}")]
ItemKindMismatch {
id: i64,
actual: &'static str,
expected: &'static str,
},
#[error("unsupported export format version {0}; upgrade sefy")]
UnsupportedExport(u32),
#[error("this is not a sefy export: {0}")]
UnreadableExport(String),
#[error("item {index} in the export is malformed: {reason}")]
MalformedExport {
index: usize,
reason: String,
},
#[error("key derivation failed")]
KeyDerivation,
#[error("system random number generator unavailable")]
Random,
#[error("{context}: {source}")]
Io {
context: String,
#[source]
source: std::io::Error,
},
#[error("database error: {0}")]
Db(#[from] rusqlite::Error),
}
impl Error {
pub(crate) fn io(context: impl Into<String>, source: std::io::Error) -> Self {
Self::Io {
context: context.into(),
source,
}
}
}