bitwarden_uniffi/
error.rs

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