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 sign-in subdomain is not a valid DNS label.
19    #[error("invalid sign-in address: {0}")]
20    InvalidSignInAddress(String),
21
22    /// The requested resource was not found (1Password code 117).
23    #[error("not found")]
24    NotFound,
25
26    /// The account requires two-factor authentication to continue.
27    #[error("two-factor authentication required")]
28    TwoFactorRequired,
29
30    /// A submitted two-factor code was rejected.
31    #[error("two-factor authentication failed")]
32    TwoFactorFailed,
33
34    /// Decryption of a server payload failed.
35    #[error("decryption failed")]
36    Decryption,
37
38    /// A server response could not be parsed.
39    #[error("failed to parse server response")]
40    Parse,
41
42    /// An item, category, or auth method that is not supported yet.
43    #[error("unsupported: {0}")]
44    Unsupported(String),
45
46    /// An invariant was violated: malformed input, a size mismatch, or a "should not happen" case.
47    #[error("internal error: {0}")]
48    Internal(String),
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn errors_describe_themselves() {
57        assert_eq!(
58            OnePasswordError::Network("timed out".into()).to_string(),
59            "network error: timed out"
60        );
61        assert_eq!(
62            OnePasswordError::Unsupported("Duo".into()).to_string(),
63            "unsupported: Duo"
64        );
65        assert_eq!(
66            OnePasswordError::BadCredentials.to_string(),
67            "invalid credentials"
68        );
69    }
70}