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("Serializing {item} for TLS")]
23    TlsSerialize {
24        item: &'static str,
25        #[source]
26        source: tls_codec::Error,
27    },
28    #[error("Deserializing {item} for TLS")]
29    TlsDeserialize {
30        item: &'static str,
31        #[source]
32        source: tls_codec::Error,
33    },
34    #[error(transparent)]
35    E2EIdentity(#[from] e2e_identity::Error),
36    #[error(transparent)]
37    Keystore(#[from] crate::KeystoreError),
38    #[error(transparent)]
39    Mls(#[from] crate::MlsError),
40    #[error("{0}")]
41    Leaf(#[from] crate::LeafError),
42    #[error(transparent)]
43    Recursive(#[from] crate::RecursiveError),
44}
45
46impl Error {
47    pub fn tls_serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
48        move |source| Self::TlsSerialize { item, source }
49    }
50
51    pub fn tls_deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
52        move |source| Self::TlsDeserialize { item, source }
53    }
54}