core_crypto/transaction_context/
error.rs

1// We allow missing documentation in the error module because the types are generally self-descriptive.
2#![allow(missing_docs)]
3
4use crate::mls::conversation::pending_conversation::PendingConversation;
5
6use super::e2e_identity;
7
8/// A module-specific [Result][core::result::Result] type with a default error variant.
9pub type Result<T, E = Error> = core::result::Result<T, E>;
10
11/// Errors produced during a transaction
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14    #[error("caller error: {0}")]
15    CallerError(&'static str),
16    #[error("This transaction context has already been finished and can no longer be used.")]
17    InvalidTransactionContext,
18    #[error("The conversation with the specified id is pending")]
19    PendingConversation(PendingConversation),
20    #[error("Couldn't find client")]
21    ClientNotFound(crate::prelude::ClientId),
22    #[error("Proteus client hasn't been initialized")]
23    ProteusNotInitialized,
24    #[error("Serializing {item} for TLS")]
25    TlsSerialize {
26        item: &'static str,
27        #[source]
28        source: tls_codec::Error,
29    },
30    #[error("Deserializing {item} for TLS")]
31    TlsDeserialize {
32        item: &'static str,
33        #[source]
34        source: tls_codec::Error,
35    },
36    #[error(transparent)]
37    E2EIdentity(#[from] e2e_identity::Error),
38    #[error(transparent)]
39    Keystore(#[from] crate::KeystoreError),
40    #[error(transparent)]
41    Mls(#[from] crate::MlsError),
42    #[error("{0}")]
43    Leaf(#[from] crate::LeafError),
44    #[error(transparent)]
45    Recursive(#[from] crate::RecursiveError),
46}
47
48impl Error {
49    pub fn tls_serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
50        move |source| Self::TlsSerialize { item, source }
51    }
52
53    pub fn tls_deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
54        move |source| Self::TlsDeserialize { item, source }
55    }
56}