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 Proteus(#[from] ProteusError),
58 #[error(transparent)]
60 Recursive(#[from] RecursiveError),
61}
62
63pub trait InnermostErrorMessage {
72 fn innermost_error_message(&self) -> String;
74}
75
76impl<E: std::error::Error> InnermostErrorMessage for E {
77 fn innermost_error_message(&self) -> String {
78 let mut err: &dyn std::error::Error = self;
79 while let Some(source) = err.source() {
80 err = source;
81 }
82 err.to_string()
83 }
84}
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 #[test]
91 fn can_unpack_wrapped_error() {
92 let inner = Error::InvalidTransactionContext;
93 let outer = RecursiveError::root("wrapping the inner for test purposes")(inner);
94 let message = outer.innermost_error_message();
95 assert_eq!(message, Error::InvalidTransactionContext.to_string());
96 }
97}