matrix_sdk_sqlite/
error.rs1use deadpool_sqlite::{CreatePoolError, PoolError};
16#[cfg(feature = "event-cache")]
17use matrix_sdk_base::event_cache::store::EventCacheStoreError;
18#[cfg(feature = "state-store")]
19use matrix_sdk_base::store::StoreError as StateStoreError;
20#[cfg(feature = "crypto-store")]
21use matrix_sdk_crypto::CryptoStoreError;
22use thiserror::Error;
23use tokio::io;
24
25#[derive(Error, Debug)]
27#[non_exhaustive]
28pub enum OpenStoreError {
29 #[error("Failed to create the database's parent directory")]
31 CreateDir(#[source] io::Error),
32
33 #[error(transparent)]
35 CreatePool(#[from] CreatePoolError),
36
37 #[error("Failed to load database version")]
39 LoadVersion(#[source] rusqlite::Error),
40
41 #[error("Missing database version")]
43 MissingVersion,
44
45 #[error("Invalid database version")]
47 InvalidVersion,
48
49 #[error("Failed to run migrations")]
51 Migration(#[from] Error),
52
53 #[error(transparent)]
55 Pool(#[from] PoolError),
56
57 #[error("Failed to initialize the store cipher")]
59 InitCipher(#[from] matrix_sdk_store_encryption::Error),
60
61 #[error("Failed to load the store cipher from the DB")]
63 LoadCipher(#[source] rusqlite::Error),
64
65 #[error("Failed to save the store cipher to the DB")]
67 SaveCipher(#[source] rusqlite::Error),
68}
69
70#[derive(Debug, Error)]
71pub enum Error {
72 #[error(transparent)]
73 Sqlite(rusqlite::Error),
74
75 #[error("Failed to compute the maximum variable number from {0}")]
76 SqliteMaximumVariableNumber(i32),
77
78 #[error(transparent)]
79 Pool(PoolError),
80
81 #[error(transparent)]
82 Encode(rmp_serde::encode::Error),
83
84 #[error(transparent)]
85 Decode(rmp_serde::decode::Error),
86
87 #[error(transparent)]
88 Json(#[from] serde_json::Error),
89
90 #[error(transparent)]
91 Encryption(matrix_sdk_store_encryption::Error),
92
93 #[error("can't save/load sessions or group sessions in the store before an account is stored")]
94 AccountUnset,
95
96 #[error(transparent)]
97 Pickle(#[from] vodozemac::PickleError),
98
99 #[error("An object failed to be decrypted while unpickling")]
100 Unpickle,
101
102 #[error("Redaction failed: {0}")]
103 Redaction(#[source] ruma::canonical_json::RedactionError),
104
105 #[error("An update keyed by unique ID touched more than one entry")]
106 InconsistentUpdate,
107
108 #[error("The store contains invalid data: {details}")]
109 InvalidData { details: String },
110}
111
112macro_rules! impl_from {
113 ( $ty:ty => $enum:ident::$variant:ident ) => {
114 impl From<$ty> for $enum {
115 fn from(value: $ty) -> Self {
116 Self::$variant(value)
117 }
118 }
119 };
120}
121
122impl_from!(rusqlite::Error => Error::Sqlite);
123impl_from!(PoolError => Error::Pool);
124impl_from!(rmp_serde::encode::Error => Error::Encode);
125impl_from!(rmp_serde::decode::Error => Error::Decode);
126impl_from!(matrix_sdk_store_encryption::Error => Error::Encryption);
127
128#[cfg(feature = "crypto-store")]
129impl From<Error> for CryptoStoreError {
130 fn from(e: Error) -> Self {
131 CryptoStoreError::backend(e)
132 }
133}
134
135#[cfg(feature = "state-store")]
136impl From<Error> for StateStoreError {
137 fn from(e: Error) -> Self {
138 match e {
139 Error::Json(e) => StateStoreError::Json(e),
140 Error::Encryption(e) => StateStoreError::Encryption(e),
141 Error::Redaction(e) => StateStoreError::Redaction(e),
142 e => StateStoreError::backend(e),
143 }
144 }
145}
146
147#[cfg(feature = "event-cache")]
148impl From<Error> for EventCacheStoreError {
149 fn from(e: Error) -> Self {
150 match e {
151 Error::Encryption(e) => EventCacheStoreError::Encryption(e),
152 e => EventCacheStoreError::backend(e),
153 }
154 }
155}
156
157pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;