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