use thiserror::Error;
pub type StoreResult<T> = Result<T, StoreError>;
#[derive(Debug, Error)]
pub enum StoreError {
#[error("engine: {0}")]
Engine(String),
#[error("value codec: {0}")]
ValueCodec(String),
#[error("key decode: {0}")]
KeyDecode(String),
#[error("vault is cold; unlock required")]
Cold,
#[error("crypto: {0}")]
Crypto(String),
#[error("collection not found: {0}")]
CollectionNotFound(String),
#[error("reserved collection name: {0}")]
ReservedName(String),
#[error("store format version {found} is newer than supported {supported}; upgrade the software")]
SchemaTooNew { found: u32, supported: u32 },
#[error("schema: {0}")]
Schema(String),
#[error("row compression: {0}")]
Compression(String),
}
impl StoreError {
pub(crate) fn engine(e: impl std::fmt::Display) -> Self {
StoreError::Engine(e.to_string())
}
pub(crate) fn value_codec(e: impl std::fmt::Display) -> Self {
StoreError::ValueCodec(e.to_string())
}
pub(crate) fn key_decode(msg: impl Into<String>) -> Self {
StoreError::KeyDecode(msg.into())
}
}