Skip to main content

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::cross_process_lock::CrossProcessLockError;
19#[cfg(feature = "e2e-encryption")]
20use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError};
21use thiserror::Error;
22
23use crate::{event_cache::store::EventCacheStoreError, media::store::MediaStoreError};
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 in the media store.
53    #[error(transparent)]
54    MediaStore(#[from] MediaStoreError),
55
56    /// An error happened while attempting to lock the event cache store.
57    #[error(transparent)]
58    EventCacheLock(#[from] CrossProcessLockError),
59
60    /// An error occurred in the crypto store.
61    #[cfg(feature = "e2e-encryption")]
62    #[error(transparent)]
63    CryptoStore(#[from] CryptoStoreError),
64
65    /// An error occurred during a E2EE operation.
66    #[cfg(feature = "e2e-encryption")]
67    #[error(transparent)]
68    OlmError(#[from] OlmError),
69
70    /// An error occurred during a group E2EE operation.
71    #[cfg(feature = "e2e-encryption")]
72    #[error(transparent)]
73    MegolmError(#[from] MegolmError),
74
75    /// An error caused by calling the `BaseClient::receive_all_members`
76    /// function with invalid parameters
77    #[error("receive_all_members function was called with invalid parameters")]
78    InvalidReceiveMembersParameters,
79
80    /// This request failed because the local data wasn't sufficient.
81    #[error("Local cache doesn't contain all necessary data to perform the action.")]
82    InsufficientData,
83
84    /// There was a [`serde_json`] deserialization error.
85    #[error(transparent)]
86    DeserializationError(#[from] serde_json::error::Error),
87}