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 Backup(#[from] vodozemac::pk_encryption::Error),
62
63 #[error(transparent)]
65 SessionCreation(#[from] SessionCreationError),
66
67 #[error(transparent)]
69 IdentifierValidation(#[from] IdParseError),
70
71 #[error(transparent)]
73 Serialization(#[from] SerdeError),
74
75 #[error(
77 "The database format changed in an incompatible way, current \
78 version: {0}, latest version: {1}"
79 )]
80 UnsupportedDatabaseVersion(usize, usize),
81
82 #[error(transparent)]
84 Backend(Box<dyn std::error::Error + Send + Sync>),
85
86 #[error("invalid lock generation: {0}")]
88 InvalidLockGeneration(String),
89}
90
91impl CryptoStoreError {
92 #[inline]
96 pub fn backend<E>(error: E) -> Self
97 where
98 E: std::error::Error + Send + Sync + 'static,
99 {
100 Self::Backend(Box::new(error))
101 }
102}
103
104impl From<Infallible> for CryptoStoreError {
105 fn from(never: Infallible) -> Self {
106 match never {}
107 }
108}