Skip to main content

ping_core/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("storage error: {0}")]
8    Storage(String),
9
10    #[error("transport error: {0}")]
11    Transport(String),
12
13    #[error("mls protocol error: {0}")]
14    Mls(String),
15
16    #[error("identity error: {0}")]
17    Identity(String),
18
19    #[error("unknown conversation: {0}")]
20    UnknownConversation(String),
21
22    #[error("unknown device: {0}")]
23    UnknownDevice(String),
24
25    #[error("epoch occupied: caller must rebase on the new epoch and retry")]
26    EpochOccupied,
27
28    #[error("codec error: {0}")]
29    Codec(String),
30
31    #[error("invalid input: {0}")]
32    Invalid(String),
33
34    #[error("not initialised")]
35    NotInitialised,
36}
37
38impl Error {
39    pub(crate) fn mls<E: std::fmt::Display>(e: E) -> Self {
40        Error::Mls(e.to_string())
41    }
42    pub(crate) fn codec<E: std::fmt::Display>(e: E) -> Self {
43        Error::Codec(e.to_string())
44    }
45}