bitwarden_uniffi/
error.rs1use std::fmt::{Display, Formatter};
2
3use bitwarden_exporters::ExportError;
4use bitwarden_generators::{PassphraseError, PasswordError, UsernameError};
5
6#[derive(uniffi::Error, Debug)]
9#[uniffi(flat_error)]
10pub enum BitwardenError {
11 E(Error),
12 ConversionError(Box<dyn std::error::Error + Send + Sync>),
13}
14
15impl From<Error> for BitwardenError {
16 fn from(e: Error) -> Self {
17 Self::E(e)
18 }
19}
20
21impl Display for BitwardenError {
22 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23 match self {
24 Self::E(e) => Display::fmt(e, f),
25 Self::ConversionError(e) => Display::fmt(e, f),
26 }
27 }
28}
29
30impl std::error::Error for BitwardenError {
31 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
32 match self {
33 BitwardenError::E(e) => Some(e),
34 BitwardenError::ConversionError(e) => Some(e.as_ref()),
35 }
36 }
37}
38
39pub type Result<T, E = BitwardenError> = std::result::Result<T, E>;
40
41#[derive(thiserror::Error, Debug)]
42pub enum Error {
43 #[error(transparent)]
44 Api(#[from] bitwarden_core::ApiError),
45 #[error(transparent)]
46 DeriveKeyConnector(#[from] bitwarden_core::key_management::crypto::DeriveKeyConnectorError),
47 #[error(transparent)]
48 EncryptionSettings(
49 #[from] bitwarden_core::client::encryption_settings::EncryptionSettingsError,
50 ),
51 #[error(transparent)]
52 EnrollAdminPasswordReset(
53 #[from] bitwarden_core::key_management::crypto::EnrollAdminPasswordResetError,
54 ),
55 #[error(transparent)]
56 MobileCrypto(#[from] bitwarden_core::key_management::crypto::CryptoClientError),
57 #[error(transparent)]
58 AuthValidate(#[from] bitwarden_core::auth::AuthValidateError),
59 #[error(transparent)]
60 ApproveAuthRequest(#[from] bitwarden_core::auth::ApproveAuthRequestError),
61 #[error(transparent)]
62 TrustDevice(#[from] bitwarden_core::auth::auth_client::TrustDeviceError),
63
64 #[error(transparent)]
65 Fingerprint(#[from] bitwarden_core::platform::FingerprintError),
66 #[error(transparent)]
67 UserFingerprint(#[from] bitwarden_core::platform::UserFingerprintError),
68
69 #[error(transparent)]
70 Crypto(#[from] bitwarden_crypto::CryptoError),
71
72 #[error(transparent)]
73 StateRegistry(#[from] bitwarden_state::registry::StateRegistryError),
74
75 #[error(transparent)]
77 Username(#[from] UsernameError),
78 #[error(transparent)]
79 Passphrase(#[from] PassphraseError),
80 #[error(transparent)]
81 Password(#[from] PasswordError),
82
83 #[error(transparent)]
85 Cipher(#[from] bitwarden_vault::CipherError),
86 #[error(transparent)]
87 Totp(#[from] bitwarden_vault::TotpError),
88 #[error(transparent)]
89 Decrypt(#[from] bitwarden_vault::DecryptError),
90 #[error(transparent)]
91 DecryptFile(#[from] bitwarden_vault::DecryptFileError),
92 #[error(transparent)]
93 Encrypt(#[from] bitwarden_vault::EncryptError),
94 #[error(transparent)]
95 EncryptFile(#[from] bitwarden_vault::EncryptFileError),
96
97 #[error(transparent)]
99 SendDecrypt(#[from] bitwarden_send::SendDecryptError),
100 #[error(transparent)]
101 SendDecryptFile(#[from] bitwarden_send::SendDecryptFileError),
102 #[error(transparent)]
103 SendEncrypt(#[from] bitwarden_send::SendEncryptError),
104 #[error(transparent)]
105 SendEncryptFile(#[from] bitwarden_send::SendEncryptFileError),
106
107 #[error(transparent)]
108 Export(#[from] ExportError),
109
110 #[error(transparent)]
112 MakeCredential(#[from] bitwarden_fido::MakeCredentialError),
113 #[error(transparent)]
114 GetAssertion(#[from] bitwarden_fido::GetAssertionError),
115 #[error(transparent)]
116 SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError),
117 #[error(transparent)]
118 CredentialsForAutofill(#[from] bitwarden_fido::CredentialsForAutofillError),
119 #[error(transparent)]
120 DecryptFido2AutofillCredentials(#[from] bitwarden_fido::DecryptFido2AutofillCredentialsError),
121 #[error(transparent)]
122 Fido2Client(#[from] bitwarden_fido::Fido2ClientError),
123
124 #[error(transparent)]
125 SshGeneration(#[from] bitwarden_ssh::error::KeyGenerationError),
126 #[error(transparent)]
127 SshImport(#[from] bitwarden_ssh::error::SshKeyImportError),
128}