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("key package not found: already consumed or pool exhausted")]
34 KeyPackageNotFound,
35
36 #[error("conversation stranded behind epoch (missed commit), needs recovery: {0}")]
42 EpochStranded(String),
43
44 #[error("codec error: {0}")]
45 Codec(String),
46
47 #[error("invalid input: {0}")]
48 Invalid(String),
49
50 #[error("not initialised")]
51 NotInitialised,
52}
53
54impl Error {
55 pub(crate) fn mls<E: std::fmt::Display>(e: E) -> Self {
56 Error::Mls(e.to_string())
57 }
58 pub(crate) fn codec<E: std::fmt::Display>(e: E) -> Self {
59 Error::Codec(e.to_string())
60 }
61}