1// Wire
2// Copyright (C) 2022 Wire Swiss GmbH
34// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
89// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
1314// You should have received a copy of the GNU General Public License
15// along with this program. If not, see http://www.gnu.org/licenses/.
1617// We allow missing documentation in the error module because the types are generally self-descriptive.
18#![allow(missing_docs)]
1920pub type CryptoboxMigrationError = super::WrappedContextualError<CryptoboxMigrationErrorKind>;
2122#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
23/// Wrapper for errors that can happen during a Cryptobox migration
24pub enum CryptoboxMigrationErrorKind {
25#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
26 #[error(transparent)]
27/// Rexie Error
28RexieError(rexie::Error),
29#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
30 #[error(transparent)]
31/// IndexedDB Error
32IdbError(idb::Error),
33#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
34 #[error(transparent)]
35/// Error when parsing/serializing JSON payloads from the WASM boundary
36JsonParseError(#[from] serde_wasm_bindgen::Error),
37#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
38 #[error(transparent)]
39/// Error when decoding base64
40Base64DecodeError(#[from] base64::DecodeError),
41#[error("The targeted value does not possess the targeted key ({0})")]
42/// Error when trying to fetch a certain key from a structured value
43MissingKeyInValue(String),
44#[error("The value cannot be coerced to the {0} type")]
45/// Error when trying to coerce a certain value to a certain type
46WrongValueType(String),
47#[cfg_attr(target_family = "wasm", error("The provided path [{0}] could not be found."))]
48 #[cfg_attr(
49 not(target_family = "wasm"),
50 error("The provided path store [{0}] is either non-existent or has an incorrect shape.")
51 )]
52/// Error when trying to open a Cryptobox store that doesn't exist
53ProvidedPathDoesNotExist(String),
54#[error("The Cryptobox identity at path [{0}] could not be found.")]
55/// Error when inspecting a Cryptobox store that doesn't contain an Identity
56IdentityNotFound(String),
57#[cfg(all(feature = "cryptobox-migrate", not(target_family = "wasm")))]
58 #[error(transparent)]
59Io(#[from] std::io::Error),
60#[cfg(feature = "cryptobox-migrate")]
61 #[error(transparent)]
62ParseInt(#[from] std::num::ParseIntError),
63}
6465#[cfg(all(feature = "cryptobox-migrate", target_family = "wasm"))]
66impl From<rexie::Error> for CryptoboxMigrationErrorKind {
67fn from(e: rexie::Error) -> Self {
68match e {
69 rexie::Error::IdbError(e) => Self::IdbError(e),
70_ => Self::RexieError(e),
71 }
72 }
73}