1mod keystore;
2mod leaf;
3mod mls;
4mod proteus;
5mod recursive;
6mod wrapper;
7
8pub use keystore::KeystoreError;
9pub use leaf::LeafError;
10pub use mls::{MlsError, MlsErrorKind};
11pub use proteus::{ProteusError, ProteusErrorKind};
12pub use recursive::{RecursiveError, ToRecursiveError};
13
14pub type Result<T, E = Error> = core::result::Result<T, E>;
16
17#[derive(Debug, thiserror::Error)]
19pub enum Error {
20 #[cfg_attr(
23 target_family = "wasm",
24 error(
25 "This transaction context has already been finished. You most likely used the context outside the callback
26 or you forget to `await` a Promise inside the transaction callback."
27 )
28 )]
29 #[cfg_attr(
30 not(target_family = "wasm"),
31 error("This transaction context has already been finished and can no longer be used.")
32 )]
33 InvalidTransactionContext,
34 #[error("Proteus client hasn't been initialized")]
36 ProteusNotInitialized,
37 #[error("The mls transport callbacks needed for CoreCrypto to operate were not set")]
39 MlsTransportNotProvided,
40 #[error("Error during mls transport: {0}")]
42 ErrorDuringMlsTransport(String),
43 #[error("This item requires a feature that the core-crypto library was built without: {0}")]
45 FeatureDisabled(&'static str),
46 #[error(transparent)]
48 Keystore(#[from] KeystoreError),
49 #[error("Invalid history secret: {0}")]
51 InvalidHistorySecret(&'static str),
52 #[error(transparent)]
54 Mls(#[from] MlsError),
55 #[error(transparent)]
57 E2eIdentity(#[from] wire_e2e_identity::E2eIdentityError),
58 #[error(transparent)]
60 Proteus(#[from] ProteusError),
61 #[error(transparent)]
63 Recursive(#[from] RecursiveError),
64}
65
66pub trait InnermostErrorMessage {
75 fn innermost_error_message(&self) -> String;
77}
78
79impl<E: std::error::Error> InnermostErrorMessage for E {
80 fn innermost_error_message(&self) -> String {
81 let mut err: &dyn std::error::Error = self;
82 while let Some(source) = err.source() {
83 err = source;
84 }
85 err.to_string()
86 }
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92
93 #[test]
94 fn can_unpack_wrapped_error() {
95 let inner = Error::InvalidTransactionContext;
96 let outer = RecursiveError::root("wrapping the inner for test purposes")(inner);
97 let message = outer.innermost_error_message();
98 assert_eq!(message, Error::InvalidTransactionContext.to_string());
99 }
100}