Skip to main content

core_crypto/mls/conversation/
error.rs

1//! MLS conversation errors
2
3// We allow missing documentation in the error module because the types are generally self-descriptive.
4#![expect(missing_docs)]
5
6use crate::ClientId;
7
8pub type Result<T, E = Error> = core::result::Result<T, E>;
9
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    #[error("Member with id {_0} doesn't exist")]
13    MemberNotFound(ClientId),
14    #[error(
15        "The tnt message counter has overflowed. You sent 2^32 targeted or transient messages in this epoch. Increment
16        the epoch and try again."
17    )]
18    TntMessageCounterOverflow,
19    /// Message rejected by the delivery service
20    #[error("Message rejected by the delivery service. Reason: {reason}")]
21    MessageRejected {
22        /// Why was the message rejected by the delivery service?
23        reason: String,
24    },
25    #[error("MLS Client was not initialized the right way")]
26    IdentityInitializationError,
27    #[error("MLS group is in an invalid state: {0}")]
28    MlsGroupInvalidState(&'static str),
29    #[error("MLS message is in an invalid state: {0}")]
30    MlsMessageInvalidState(&'static str),
31    #[error("The group lacks an ExternalSender extension whereas it should have at least one")]
32    MissingExternalSenderExtension,
33    #[error("unexpectedly failed to retrieve group info")]
34    MissingGroupInfo,
35    #[error("Couldn't find pending commit")]
36    PendingCommitNotFound,
37    #[error(
38        "Happens when a client creates a commit, sends it to the DS which accepts it but then client \
39    clears this pending commit and creates another commit. This is triggered when the client tries to decrypt the original commit.\
40    This means something is very wrong in the client's code and has to be fixed immediately"
41    )]
42    ClearingPendingCommitError,
43    #[error("Tried to decrypt a commit created by self which is likely to have been replayed by the DS")]
44    SelfCommitIgnored,
45    #[error("caller error: {0}")]
46    CallerError(&'static str),
47    /// This happens when the DS cannot flag KeyPackages as claimed or not. In this scenario, a client
48    /// requests their old KeyPackages to be deleted but one has already been claimed by another client to create a
49    /// Welcome. In that case the only solution is that the client receiving such a Welcome tries to join the group
50    /// with an External Commit instead
51    #[error(
52        "Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit"
53    )]
54    OrphanWelcome,
55    #[error("Operation couldn't be performed due to duplicate signature for clients: {affected_clients:?}")]
56    DuplicateSignature {
57        affected_clients: Vec<(crate::ClientId, crate::ClientId)>,
58    },
59    #[error("this conversation has been invalidated due to its `Session` reference dropping")]
60    SessionDropped,
61    #[error(transparent)]
62    Tls(#[from] crate::TlsCodecError),
63    #[error(transparent)]
64    OpenMls(#[from] crate::OpenMlsError),
65    #[error(transparent)]
66    Keystore(#[from] crate::KeystoreError),
67    #[error(transparent)]
68    Recursive(#[from] crate::RecursiveError),
69}
70
71impl Error {
72    pub(super) fn savepoint(
73        context: &'static str,
74    ) -> Box<dyn FnOnce(core_crypto_keystore::CryptoKeystoreError) -> Self> {
75        Box::new(move |err| crate::KeystoreError::wrap(context)(err).into())
76    }
77}