Skip to main content

walletkit_db/
error.rs

1//! Error types for the storage primitives layer.
2
3use crate::sqlite::Error as DbError;
4
5/// Result alias for [`StoreError`].
6pub type StoreResult<T> = Result<T, StoreError>;
7
8/// Errors raised by the storage primitives (vault, blobs, envelope, lock).
9///
10/// Variants carry a stringified detail rather than a concrete cause to keep
11/// the error type cheap to clone and FFI-friendly when consumers wrap it in
12/// their own typed error.
13#[derive(Debug, thiserror::Error)]
14pub enum StoreError {
15    /// Errors coming from the device keystore.
16    #[error("keystore error: {0}")]
17    Keystore(String),
18    /// Errors coming from the blob store.
19    #[error("blob store error: {0}")]
20    BlobStore(String),
21    /// Errors coming from the storage lock.
22    #[error("storage lock error: {0}")]
23    Lock(String),
24    /// Serialization / deserialization failures (envelope CBOR, etc.).
25    #[error("serialization error: {0}")]
26    Serialization(String),
27    /// Cryptographic failures (AEAD seal/open, RNG, etc.).
28    #[error("crypto error: {0}")]
29    Crypto(String),
30    /// Invalid or malformed key envelope (e.g. wrong length, bad format).
31    #[error("invalid envelope: {0}")]
32    InvalidEnvelope(String),
33    /// Envelope written by an unsupported version.
34    #[error("unsupported envelope version: {0}")]
35    UnsupportedEnvelopeVersion(u32),
36    /// Underlying database error from the encrypted-`SQLite` wrapper.
37    #[error("database error: {0}")]
38    Db(#[from] DbError),
39    /// `PRAGMA integrity_check` reported corruption.
40    #[error("integrity check failed: {0}")]
41    IntegrityCheckFailed(String),
42}