core_crypto/error/
proteus.rs1pub type ProteusError = super::wrapper::WrappedContextualError<ProteusErrorKind>;
3
4#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
6pub enum ProteusErrorKind {
7 #[cfg(feature = "proteus")]
8 #[error(transparent)]
9 ProteusDecodeError(#[from] proteus_wasm::DecodeError),
11 #[cfg(feature = "proteus")]
12 #[error(transparent)]
13 ProteusEncodeError(#[from] proteus_wasm::EncodeError),
15 #[cfg(feature = "proteus")]
16 #[error(transparent)]
17 ProteusInternalError(#[from] proteus_wasm::error::ProteusError),
19 #[cfg(feature = "proteus")]
20 #[error(transparent)]
21 ProteusSessionError(#[from] proteus_wasm::session::Error<core_crypto_keystore::CryptoKeystoreError>),
23 #[cfg(feature = "proteus")]
25 #[error("{0}")]
26 Leaf(#[from] crate::LeafError),
27}
28
29impl ProteusErrorKind {
30 #[cfg(feature = "proteus")]
31 fn proteus_error_code(&self) -> Option<proteus_traits::ProteusErrorKind> {
32 use proteus_traits::ProteusErrorCode as _;
33 let mut out = match self {
34 ProteusErrorKind::ProteusDecodeError(decode_error) => Some(decode_error.code()),
35 ProteusErrorKind::ProteusEncodeError(encode_error) => Some(encode_error.code()),
36 ProteusErrorKind::ProteusInternalError(proteus_error) => Some(proteus_error.code()),
37 ProteusErrorKind::ProteusSessionError(session_error) => Some(session_error.code()),
38 ProteusErrorKind::Leaf(crate::LeafError::ConversationNotFound(_)) => {
39 Some(proteus_traits::ProteusErrorKind::SessionStateNotFoundForTag)
40 }
41 ProteusErrorKind::Leaf(_) => None,
42 };
43 if out == Some(proteus_traits::ProteusErrorKind::None) {
44 out = None;
45 }
46 out
47 }
48 pub fn error_code(&self) -> Option<u16> {
50 cfg_if::cfg_if! {
51 if #[cfg(feature = "proteus")] {
52 self.proteus_error_code().map(|code| code as u16)
53 } else {
54 None
55 }
56 }
57 }
58}