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 #[error("This transaction context has already been finished and can no longer be used.")]
23 InvalidTransactionContext,
24 #[error("Proteus client hasn't been initialized")]
26 ProteusNotInitialized,
27 #[error("The mls transport callbacks needed for CoreCrypto to operate were not set")]
29 MlsTransportNotProvided,
30 #[error("Error during mls transport: {0}")]
32 ErrorDuringMlsTransport(String),
33 #[error("This item requires a feature that the core-crypto library was built without: {0}")]
35 FeatureDisabled(&'static str),
36 #[error(transparent)]
38 Keystore(#[from] KeystoreError),
39 #[error("Invalid history secret: {0}")]
41 InvalidHistorySecret(&'static str),
42 #[error(transparent)]
44 Mls(#[from] MlsError),
45 #[error(transparent)]
47 Proteus(#[from] ProteusError),
48 #[error(transparent)]
50 Recursive(#[from] RecursiveError),
51}
52
53pub trait InnermostErrorMessage {
62 fn innermost_error_message(&self) -> String;
64}
65
66impl<E: std::error::Error> InnermostErrorMessage for E {
67 fn innermost_error_message(&self) -> String {
68 let mut err: &dyn std::error::Error = self;
69 while let Some(source) = err.source() {
70 err = source;
71 }
72 err.to_string()
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn can_unpack_wrapped_error() {
82 let inner = Error::InvalidTransactionContext;
83 let outer = RecursiveError::root("wrapping the inner for test purposes")(inner);
84 let message = outer.innermost_error_message();
85 assert_eq!(message, Error::InvalidTransactionContext.to_string());
86 }
87}