matrix_sdk_base/error.rs
1// Copyright 2020 Damir Jelić
2// Copyright 2020 The Matrix.org Foundation C.I.C.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Error conditions.
17
18use matrix_sdk_common::store_locks::LockStoreError;
19#[cfg(feature = "e2e-encryption")]
20use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError};
21use thiserror::Error;
22
23use crate::event_cache::store::EventCacheStoreError;
24
25/// Result type of the rust-sdk.
26pub type Result<T, E = Error> = std::result::Result<T, E>;
27
28/// Internal representation of errors.
29#[non_exhaustive]
30#[derive(Error, Debug)]
31pub enum Error {
32 /// Attempting to restore a session after the olm-machine has already been
33 /// set up fails
34 #[cfg(feature = "e2e-encryption")]
35 #[error("The olm machine has already been initialized")]
36 BadCryptoStoreState,
37
38 /// The room where a group session should be shared is not encrypted.
39 #[cfg(feature = "e2e-encryption")]
40 #[error("The room where a group session should be shared is not encrypted")]
41 EncryptionNotEnabled,
42
43 /// A generic error returned when the state store fails not due to
44 /// IO or (de)serialization.
45 #[error(transparent)]
46 StateStore(#[from] crate::store::StoreError),
47
48 /// An error happened while manipulating the event cache store.
49 #[error(transparent)]
50 EventCacheStore(#[from] EventCacheStoreError),
51
52 /// An error happened while attempting to lock the event cache store.
53 #[error(transparent)]
54 EventCacheLock(#[from] LockStoreError),
55
56 /// An error occurred in the crypto store.
57 #[cfg(feature = "e2e-encryption")]
58 #[error(transparent)]
59 CryptoStore(#[from] CryptoStoreError),
60
61 /// An error occurred during a E2EE operation.
62 #[cfg(feature = "e2e-encryption")]
63 #[error(transparent)]
64 OlmError(#[from] OlmError),
65
66 /// An error occurred during a group E2EE operation.
67 #[cfg(feature = "e2e-encryption")]
68 #[error(transparent)]
69 MegolmError(#[from] MegolmError),
70
71 /// An error caused by calling the `BaseClient::receive_all_members`
72 /// function with invalid parameters
73 #[error("receive_all_members function was called with invalid parameters")]
74 InvalidReceiveMembersParameters,
75
76 /// This request failed because the local data wasn't sufficient.
77 #[error("Local cache doesn't contain all necessary data to perform the action.")]
78 InsufficientData,
79
80 /// There was a [`serde_json`] deserialization error.
81 #[error(transparent)]
82 DeserializationError(#[from] serde_json::error::Error),
83}