Skip to main content

bitwarden_uniffi/
error.rs

1use bitwarden_exporters::ExportError;
2use bitwarden_generators::{PassphraseError, PasswordError, PasswordRulesError, UsernameError};
3
4pub type Result<T, E = BitwardenError> = std::result::Result<T, E>;
5pub type Error = BitwardenError;
6
7// Name is converted from *Error to *Exception, so we can't just name the enum Error because
8// Exception already exists
9#[derive(uniffi::Error, thiserror::Error, Debug)]
10pub enum BitwardenError {
11    #[error(transparent)]
12    Api(#[from] bitwarden_core::ApiError),
13    #[error(transparent)]
14    DeriveKeyConnector(#[from] bitwarden_core::key_management::crypto::DeriveKeyConnectorError),
15    #[error(transparent)]
16    EncryptionSettings(
17        #[from] bitwarden_core::client::encryption_settings::EncryptionSettingsError,
18    ),
19    #[error(transparent)]
20    EnrollAdminPasswordReset(
21        #[from] bitwarden_core::key_management::crypto::EnrollAdminPasswordResetError,
22    ),
23    #[error(transparent)]
24    MobileCrypto(#[from] bitwarden_core::key_management::crypto::CryptoClientError),
25    #[error(transparent)]
26    ReinitUserCrypto(#[from] bitwarden_core::key_management::crypto::ReinitUserCryptoError),
27    #[error(transparent)]
28    AuthValidate(#[from] bitwarden_core::auth::AuthValidateError),
29    #[error(transparent)]
30    ApproveAuthRequest(#[from] bitwarden_core::auth::ApproveAuthRequestError),
31    #[error(transparent)]
32    TrustDevice(#[from] bitwarden_core::auth::auth_client::TrustDeviceError),
33    #[error(transparent)]
34    Registration(#[from] bitwarden_auth::registration::RegistrationError),
35    #[error(transparent)]
36    PasswordPrelogin(#[from] bitwarden_auth::login::login_via_password::PasswordPreloginError),
37    #[error(transparent)]
38    PasswordLogin(#[from] bitwarden_auth::login::login_via_password::PasswordLoginError),
39
40    #[error(transparent)]
41    Fingerprint(#[from] bitwarden_core::platform::FingerprintError),
42    #[error(transparent)]
43    UserFingerprint(#[from] bitwarden_core::platform::UserFingerprintError),
44
45    #[error(transparent)]
46    Crypto(#[from] bitwarden_crypto::CryptoError),
47
48    #[error(transparent)]
49    StateRegistry(#[from] bitwarden_state::registry::StateRegistryError),
50
51    // Generators
52    #[error(transparent)]
53    Username(#[from] UsernameError),
54    #[error(transparent)]
55    Passphrase(#[from] PassphraseError),
56    #[error(transparent)]
57    Password(#[from] PasswordError),
58    #[error(transparent)]
59    PasswordRules(#[from] PasswordRulesError),
60
61    // Vault
62    #[error(transparent)]
63    Cipher(#[from] bitwarden_vault::CipherError),
64    #[error(transparent)]
65    Totp(#[from] bitwarden_vault::TotpError),
66    #[error(transparent)]
67    Decrypt(#[from] bitwarden_vault::DecryptError),
68    #[error(transparent)]
69    DecryptFile(#[from] bitwarden_vault::DecryptFileError),
70    #[error(transparent)]
71    Encrypt(#[from] bitwarden_vault::EncryptError),
72    #[error(transparent)]
73    EncryptFile(#[from] bitwarden_vault::EncryptFileError),
74
75    // Collections
76    #[error(transparent)]
77    CollectionDecrypt(#[from] bitwarden_collections::error::CollectionDecryptError),
78    #[error(transparent)]
79    CollectionEncrypt(#[from] bitwarden_collections::error::CollectionEncryptError),
80
81    // Send
82    #[error(transparent)]
83    SendDecrypt(#[from] bitwarden_send::SendDecryptError),
84    #[error(transparent)]
85    SendDecryptFile(#[from] bitwarden_send::SendDecryptFileError),
86    #[error(transparent)]
87    SendEncrypt(#[from] bitwarden_send::SendEncryptError),
88    #[error(transparent)]
89    SendEncryptFile(#[from] bitwarden_send::SendEncryptFileError),
90
91    #[error(transparent)]
92    Export(#[from] ExportError),
93    #[error(transparent)]
94    Import(#[from] bitwarden_importers::ImportError),
95
96    // Fido
97    #[error(transparent)]
98    MakeCredential(#[from] bitwarden_fido::MakeCredentialError),
99    #[error(transparent)]
100    GetAssertion(#[from] bitwarden_fido::GetAssertionError),
101    #[error(transparent)]
102    SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError),
103    #[error(transparent)]
104    CredentialsForAutofill(#[from] bitwarden_fido::CredentialsForAutofillError),
105    #[error(transparent)]
106    DecryptFido2AutofillCredentials(#[from] bitwarden_fido::DecryptFido2AutofillCredentialsError),
107    #[error(transparent)]
108    Fido2Client(#[from] bitwarden_fido::Fido2ClientError),
109    #[error(transparent)]
110    DeviceAuthKey(#[from] bitwarden_fido::DeviceAuthKeyError),
111
112    #[error(transparent)]
113    SshGeneration(#[from] bitwarden_ssh::error::KeyGenerationError),
114    #[error(transparent)]
115    SshImport(#[from] bitwarden_ssh::error::SshKeyImportError),
116
117    #[error(transparent)]
118    AcquireCookie(#[from] bitwarden_server_communication_config::AcquireCookieError),
119
120    #[error("Callback invocation failed")]
121    Callback,
122
123    #[error("A conversion error occurred: {0}")]
124    Conversion(String),
125}
126/// Required From implementation for UNIFFI callback error handling
127/// Converts unexpected mobile exceptions into BitwardenError
128impl From<uniffi::UnexpectedUniFFICallbackError> for BitwardenError {
129    fn from(_: uniffi::UnexpectedUniFFICallbackError) -> Self {
130        Self::Callback
131    }
132}