ruma_state_res/
error.rs

1use serde_json::Error as JsonError;
2use thiserror::Error;
3
4/// Result type for state resolution.
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// Represents the various errors that arise when resolving state.
8#[derive(Error, Debug)]
9#[non_exhaustive]
10pub enum Error {
11    /// A deserialization error.
12    #[error(transparent)]
13    SerdeJson(#[from] JsonError),
14
15    /// The given option or version is unsupported.
16    #[error("Unsupported room version: {0}")]
17    Unsupported(String),
18
19    /// The given event was not found.
20    #[error("Not found error: {0}")]
21    NotFound(String),
22
23    /// Invalid fields in the given PDU.
24    #[error("Invalid PDU: {0}")]
25    InvalidPdu(String),
26
27    /// A custom error.
28    #[error("{0}")]
29    Custom(Box<dyn std::error::Error>),
30}
31
32impl Error {
33    pub fn custom<E: std::error::Error + 'static>(e: E) -> Self {
34        Self::Custom(Box::new(e))
35    }
36}