matrix_sdk_crypto/store/
error.rs1use std::{convert::Infallible, fmt::Debug, io::Error as IoError};
16
17use ruma::{IdParseError, OwnedDeviceId, OwnedUserId};
18use serde_json::Error as SerdeError;
19use thiserror::Error;
20
21use crate::olm::SessionCreationError;
22
23pub type Result<T, E = CryptoStoreError> = std::result::Result<T, E>;
25
26#[derive(Debug, Error)]
28pub enum CryptoStoreError {
29 #[error("can't save/load sessions or group sessions in the store before an account is stored")]
32 AccountUnset,
33
34 #[error(
37 "the account in the store doesn't match the account in the constructor: \
38 expected {}:{}, got {}:{}", .expected.0, .expected.1, .got.0, .got.1
39 )]
40 MismatchedAccount {
41 expected: (OwnedUserId, OwnedDeviceId),
43 got: (OwnedUserId, OwnedDeviceId),
45 },
46
47 #[error(transparent)]
49 Io(#[from] IoError),
50
51 #[error("An object failed to be decrypted while unpickling")]
53 UnpicklingError,
54
55 #[error(transparent)]
57 Pickle(#[from] vodozemac::PickleError),
58
59 #[error(transparent)]
61 SessionCreation(#[from] SessionCreationError),
62
63 #[error(transparent)]
65 IdentifierValidation(#[from] IdParseError),
66
67 #[error(transparent)]
69 Serialization(#[from] SerdeError),
70
71 #[error(
73 "The database format changed in an incompatible way, current \
74 version: {0}, latest version: {1}"
75 )]
76 UnsupportedDatabaseVersion(usize, usize),
77
78 #[error(transparent)]
80 #[cfg(not(target_family = "wasm"))]
81 Backend(Box<dyn std::error::Error + Send + Sync>),
82
83 #[error(transparent)]
85 #[cfg(target_family = "wasm")]
86 Backend(Box<dyn std::error::Error>),
87
88 #[error("invalid lock generation: {0}")]
90 InvalidLockGeneration(String),
91}
92
93impl CryptoStoreError {
94 #[inline]
98 #[cfg(not(target_family = "wasm"))]
99 pub fn backend<E>(error: E) -> Self
100 where
101 E: std::error::Error + Send + Sync + 'static,
102 {
103 Self::Backend(Box::new(error))
104 }
105
106 #[inline]
110 #[cfg(target_family = "wasm")]
111 pub fn backend<E>(error: E) -> Self
112 where
113 E: std::error::Error + 'static,
114 {
115 Self::Backend(Box::new(error))
116 }
117}
118
119impl From<Infallible> for CryptoStoreError {
120 fn from(never: Infallible) -> Self {
121 match never {}
122 }
123}