1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use matrix_sdk_base::ruma::events::UnsignedRoomRedactionEvent;
use std::sync::PoisonError;

use crate::models::EventMeta;

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("Error in the inner MatrixSDK")]
    MatrixSdk(#[from] matrix_sdk::Error),

    #[error("Error in the MatrixSDK HTTP")]
    HttpError(#[from] matrix_sdk::HttpError),

    #[error("Not a known Acter Event")]
    UnknownEvent,

    #[error("Error De/serializing: {0}")]
    Serialization(#[from] serde_json::Error),

    #[error("Error with the matrix sdk Store")]
    Store(#[from] matrix_sdk::StoreError),

    #[error("IO Error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("Store Dirty Lock Poisoned Error.")]
    StoreDirtyPoisoned,

    #[error("Model not found at {0}.")]
    ModelNotFound(String),

    #[error("Index not found.")]
    IndexNotFound,

    #[error("Your Homeserver doesn’t have a hostname, that is required for this action.")]
    HomeserverMissesHostname,

    #[error("The client must be logged in for this interaction.")]
    ClientNotLoggedIn,

    #[error("Model {0:?} unknown")]
    UnknownModel(Option<String>),

    #[error("Failed to parse {model_type}: {msg}")]
    FailedToParse { model_type: String, msg: String },

    #[error("Id Parse Error: {0}")]
    IdParseError(#[from] matrix_sdk_base::ruma::IdParseError),

    #[error("Model {meta:?} ({model_type}): {reason:?}")]
    ModelRedacted {
        model_type: String,
        meta: EventMeta,
        reason: UnsignedRoomRedactionEvent,
    },

    #[error("{0:?} field is missing")]
    MissingField(String),

    #[error("{0}")]
    Custom(String),
}

impl<T> From<PoisonError<T>> for Error {
    fn from(_err: PoisonError<T>) -> Self {
        Self::StoreDirtyPoisoned
    }
}

pub type Result<T> = std::result::Result<T, Error>;