Skip to main content

bitwarden_importers/importers/onepassword/access/
error.rs

1//! Error type for the 1Password client.
2//!
3//! The codes noted below are 1Password server error codes.
4
5use thiserror::Error;
6
7/// Errors returned by the 1Password access library.
8#[derive(Debug, Error)]
9pub enum OnePasswordError {
10    /// Network or transport failure.
11    #[error("network error: {0}")]
12    Network(String),
13
14    /// Invalid username, password, or Secret Key (1Password code 102).
15    #[error("invalid credentials")]
16    BadCredentials,
17
18    /// The requested resource was not found (1Password code 117).
19    #[error("not found")]
20    NotFound,
21
22    /// The account requires two-factor authentication to continue.
23    #[error("two-factor authentication required")]
24    TwoFactorRequired,
25
26    /// A submitted two-factor code was rejected.
27    #[error("two-factor authentication failed")]
28    TwoFactorFailed,
29
30    /// Decryption of a server payload failed.
31    #[error("decryption failed")]
32    Decryption,
33
34    /// A server response could not be parsed.
35    #[error("failed to parse server response")]
36    Parse,
37
38    /// An item, category, or auth method that is not supported yet.
39    #[error("unsupported: {0}")]
40    Unsupported(String),
41
42    /// An invariant was violated: malformed input, a size mismatch, or a "should not happen" case.
43    #[error("internal error: {0}")]
44    Internal(String),
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn errors_describe_themselves() {
53        assert_eq!(
54            OnePasswordError::Network("timed out".into()).to_string(),
55            "network error: timed out"
56        );
57        assert_eq!(
58            OnePasswordError::Unsupported("Duo".into()).to_string(),
59            "unsupported: Duo"
60        );
61        assert_eq!(
62            OnePasswordError::BadCredentials.to_string(),
63            "invalid credentials"
64        );
65    }
66}