core_crypto/error/
cryptobox_migration.rs

1// We allow missing documentation in the error module because the types are generally self-descriptive.
2#![allow(missing_docs)]
3
4pub type CryptoboxMigrationError = super::WrappedContextualError<CryptoboxMigrationErrorKind>;
5
6#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
7/// Wrapper for errors that can happen during a Cryptobox migration
8pub enum CryptoboxMigrationErrorKind {
9    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
10    #[error(transparent)]
11    /// Rexie Error
12    RexieError(rexie::Error),
13    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
14    #[error(transparent)]
15    /// IndexedDB Error
16    IdbError(idb::Error),
17    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
18    #[error(transparent)]
19    /// Error when parsing/serializing JSON payloads from the WASM boundary
20    JsonParseError(#[from] serde_wasm_bindgen::Error),
21    #[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
22    #[error(transparent)]
23    /// Error when decoding base64
24    Base64DecodeError(#[from] base64::DecodeError),
25    #[error("The targeted value does not possess the targeted key ({0})")]
26    /// Error when trying to fetch a certain key from a structured value
27    MissingKeyInValue(String),
28    #[error("The value cannot be coerced to the {0} type")]
29    /// Error when trying to coerce a certain value to a certain type
30    WrongValueType(String),
31    #[cfg_attr(target_family = "wasm", error("The provided path [{0}] could not be found."))]
32    #[cfg_attr(
33        not(target_family = "wasm"),
34        error("The provided path store [{0}] is either non-existent or has an incorrect shape.")
35    )]
36    /// Error when trying to open a Cryptobox store that doesn't exist
37    ProvidedPathDoesNotExist(String),
38    #[error("The Cryptobox identity at path [{0}] could not be found.")]
39    /// Error when inspecting a Cryptobox store that doesn't contain an Identity
40    IdentityNotFound(String),
41    #[cfg(all(feature = "cryptobox-migrate", not(target_family = "wasm")))]
42    #[error(transparent)]
43    Io(#[from] std::io::Error),
44    #[cfg(feature = "cryptobox-migrate")]
45    #[error(transparent)]
46    ParseInt(#[from] std::num::ParseIntError),
47}
48
49#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
50impl From<rexie::Error> for CryptoboxMigrationErrorKind {
51    fn from(e: rexie::Error) -> Self {
52        match e {
53            rexie::Error::IdbError(e) => Self::IdbError(e),
54            _ => Self::RexieError(e),
55        }
56    }
57}