Skip to main content

bitwarden_uniffi/
error.rs

1use bitwarden_exporters::ExportError;
2use bitwarden_generators::{PassphraseError, PasswordError, 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    AuthValidate(#[from] bitwarden_core::auth::AuthValidateError),
27    #[error(transparent)]
28    ApproveAuthRequest(#[from] bitwarden_core::auth::ApproveAuthRequestError),
29    #[error(transparent)]
30    TrustDevice(#[from] bitwarden_core::auth::auth_client::TrustDeviceError),
31    #[error(transparent)]
32    Registration(#[from] bitwarden_auth::registration::RegistrationError),
33
34    #[error(transparent)]
35    Fingerprint(#[from] bitwarden_core::platform::FingerprintError),
36    #[error(transparent)]
37    UserFingerprint(#[from] bitwarden_core::platform::UserFingerprintError),
38
39    #[error(transparent)]
40    Crypto(#[from] bitwarden_crypto::CryptoError),
41
42    #[error(transparent)]
43    StateRegistry(#[from] bitwarden_state::registry::StateRegistryError),
44
45    // Generators
46    #[error(transparent)]
47    Username(#[from] UsernameError),
48    #[error(transparent)]
49    Passphrase(#[from] PassphraseError),
50    #[error(transparent)]
51    Password(#[from] PasswordError),
52
53    // Vault
54    #[error(transparent)]
55    Cipher(#[from] bitwarden_vault::CipherError),
56    #[error(transparent)]
57    Totp(#[from] bitwarden_vault::TotpError),
58    #[error(transparent)]
59    Decrypt(#[from] bitwarden_vault::DecryptError),
60    #[error(transparent)]
61    DecryptFile(#[from] bitwarden_vault::DecryptFileError),
62    #[error(transparent)]
63    Encrypt(#[from] bitwarden_vault::EncryptError),
64    #[error(transparent)]
65    EncryptFile(#[from] bitwarden_vault::EncryptFileError),
66
67    // Send
68    #[error(transparent)]
69    SendDecrypt(#[from] bitwarden_send::SendDecryptError),
70    #[error(transparent)]
71    SendDecryptFile(#[from] bitwarden_send::SendDecryptFileError),
72    #[error(transparent)]
73    SendEncrypt(#[from] bitwarden_send::SendEncryptError),
74    #[error(transparent)]
75    SendEncryptFile(#[from] bitwarden_send::SendEncryptFileError),
76
77    #[error(transparent)]
78    Export(#[from] ExportError),
79
80    // Fido
81    #[error(transparent)]
82    MakeCredential(#[from] bitwarden_fido::MakeCredentialError),
83    #[error(transparent)]
84    GetAssertion(#[from] bitwarden_fido::GetAssertionError),
85    #[error(transparent)]
86    SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError),
87    #[error(transparent)]
88    CredentialsForAutofill(#[from] bitwarden_fido::CredentialsForAutofillError),
89    #[error(transparent)]
90    DecryptFido2AutofillCredentials(#[from] bitwarden_fido::DecryptFido2AutofillCredentialsError),
91    #[error(transparent)]
92    Fido2Client(#[from] bitwarden_fido::Fido2ClientError),
93
94    #[error(transparent)]
95    SshGeneration(#[from] bitwarden_ssh::error::KeyGenerationError),
96    #[error(transparent)]
97    SshImport(#[from] bitwarden_ssh::error::SshKeyImportError),
98
99    #[error(transparent)]
100    AcquireCookie(#[from] bitwarden_server_communication_config::AcquireCookieError),
101
102    #[error("Callback invocation failed")]
103    CallbackError,
104
105    #[error("A conversion error occurred: {0}")]
106    Conversion(String),
107}
108/// Required From implementation for UNIFFI callback error handling
109/// Converts unexpected mobile exceptions into BitwardenError
110impl From<uniffi::UnexpectedUniFFICallbackError> for BitwardenError {
111    fn from(_: uniffi::UnexpectedUniFFICallbackError) -> Self {
112        Self::CallbackError
113    }
114}