1mod cryptobox_migration;
2mod keystore;
3mod leaf;
4mod mls;
5mod proteus;
6mod recursive;
7mod wrapper;
8
9pub use cryptobox_migration::{CryptoboxMigrationError, CryptoboxMigrationErrorKind};
10pub use keystore::KeystoreError;
11pub use leaf::LeafError;
12pub use mls::{MlsError, MlsErrorKind};
13pub use proteus::{ProteusError, ProteusErrorKind};
14pub use recursive::{RecursiveError, ToRecursiveError};
15pub(crate) use wrapper::WrappedContextualError;
16
17pub type Result<T, E = Error> = core::result::Result<T, E>;
19
20#[derive(Debug, thiserror::Error)]
22pub enum Error {
23 #[error("This transaction context has already been finished and can no longer be used.")]
25 InvalidTransactionContext,
26 #[error("Proteus client hasn't been initialized")]
28 ProteusNotInitialized,
29 #[error("The mls transport callbacks needed for CoreCrypto to operate were not set")]
31 MlsTransportNotProvided,
32 #[error("Error during mls transport: {0}")]
34 ErrorDuringMlsTransport(String),
35 #[error("This item requires a feature that the core-crypto library was built without: {0}")]
37 FeatureDisabled(&'static str),
38 #[error(transparent)]
40 Keystore(#[from] KeystoreError),
41 #[error("Invalid history secret: {0}")]
43 InvalidHistorySecret(&'static str),
44 #[error(transparent)]
46 Mls(#[from] MlsError),
47 #[error(transparent)]
49 Proteus(#[from] ProteusError),
50 #[error(transparent)]
52 CryptoboxMigration(#[from] CryptoboxMigrationError),
53 #[error(transparent)]
55 Recursive(#[from] RecursiveError),
56}
57
58pub trait InnermostErrorMessage {
67 fn innermost_error_message(&self) -> String;
69}
70
71impl<E: std::error::Error> InnermostErrorMessage for E {
72 fn innermost_error_message(&self) -> String {
73 let mut err: &dyn std::error::Error = self;
74 while let Some(source) = err.source() {
75 err = source;
76 }
77 err.to_string()
78 }
79}
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn can_unpack_wrapped_error() {
87 let inner = Error::InvalidTransactionContext;
88 let outer = RecursiveError::root("wrapping the inner for test purposes")(inner);
89 let message = outer.innermost_error_message();
90 assert_eq!(message, Error::InvalidTransactionContext.to_string());
91 }
92}