1use std::{io, path::PathBuf, result};
2
3#[cfg(feature = "autoconfig")]
4use http::ureq::http::{StatusCode, Uri};
5use thiserror::Error;
6
7pub type Result<T> = result::Result<T, Error>;
9
10#[derive(Debug, Error)]
12pub enum Error {
13 #[error("cannot get configuration of account {0}")]
14 GetAccountConfigNotFoundError(String),
15
16 #[cfg(feature = "sync")]
17 #[error("cannot get sync directory from XDG_DATA_HOME")]
18 GetXdgDataDirSyncError,
19 #[cfg(feature = "sync")]
20 #[error("cannot get invalid or missing synchronization directory {1}")]
21 GetSyncDirInvalidError(#[source] shellexpand_utils::Error, PathBuf),
22
23 #[error("cannot parse download file name from {0}")]
24 ParseDownloadFileNameError(PathBuf),
25 #[error("cannot get file name from path {0}")]
26 GetFileNameFromPathSyncError(PathBuf),
27 #[cfg(feature = "oauth2")]
28 #[error("cannot create oauth2 client")]
29 InitOauthClientError(#[source] oauth::v2_0::Error),
30 #[cfg(feature = "oauth2")]
31 #[error("cannot create oauth2 client")]
32 BuildOauthClientError(#[source] oauth::v2_0::Error),
33 #[cfg(feature = "oauth2")]
34 #[error("cannot wait for oauth2 redirection error")]
35 WaitForOauthRedirectionError(#[source] oauth::v2_0::Error),
36
37 #[error("cannot get oauth2 access token from global keyring")]
38 GetAccessTokenOauthError(#[source] secret::Error),
39 #[error("cannot set oauth2 access token")]
40 SetAccessTokenOauthError(#[source] secret::Error),
41 #[cfg(feature = "oauth2")]
42 #[error("cannot refresh oauth2 access token")]
43 RefreshAccessTokenOauthError(#[source] oauth::v2_0::Error),
44 #[error("cannot delete oauth2 access token from global keyring")]
45 DeleteAccessTokenOauthError(#[source] secret::Error),
46
47 #[error("cannot get oauth2 refresh token")]
48 GetRefreshTokenOauthError(#[source] secret::Error),
49 #[error("cannot set oauth2 refresh token")]
50 SetRefreshTokenOauthError(#[source] secret::Error),
51 #[error("cannot delete oauth2 refresh token from global keyring")]
52 DeleteRefreshTokenOauthError(#[source] secret::Error),
53
54 #[error("cannot get oauth2 client secret from user")]
55 GetClientSecretFromUserOauthError(#[source] io::Error),
56 #[error("cannot get oauth2 client secret from global keyring")]
57 GetClientSecretFromKeyringOauthError(#[source] secret::Error),
58 #[error("cannot save oauth2 client secret into global keyring")]
59 SetClientSecretIntoKeyringOauthError(#[source] secret::Error),
60 #[error("cannot delete oauth2 client secret from global keyring")]
61 DeleteClientSecretOauthError(#[source] secret::Error),
62
63 #[error("cannot get available port")]
64 GetAvailablePortError,
65 #[error("cannot get password from user")]
66 GetFromUserError(#[source] io::Error),
67 #[error("cannot get password from global keyring")]
68 GetFromKeyringError(#[source] secret::Error),
69 #[error("cannot save password into global keyring")]
70 SetIntoKeyringError(#[source] secret::Error),
71 #[error("cannot delete password from global keyring")]
72 DeletePasswordFromKeyringError(#[source] secret::Error),
73 #[cfg(feature = "pgp-native")]
74 #[error("cannot delete pgp key from keyring")]
75 DeletePgpKeyFromKeyringError(#[source] keyring::Error),
76 #[cfg(feature = "pgp-native")]
77 #[error("cannot delete pgp key at {1}")]
78 DeletePgpKeyAtPathError(#[source] io::Error, PathBuf),
79 #[cfg(feature = "pgp-native")]
80 #[error("cannot generate pgp key pair for {1}")]
81 GeneratePgpKeyPairError(#[source] pgp::Error, String),
82 #[cfg(feature = "pgp-native")]
83 #[error("cannot export secret key to armored string")]
84 ExportSecretKeyToArmoredStringError(#[source] pgp::native::errors::Error),
85 #[cfg(feature = "pgp-native")]
86 #[error("cannot export public key to armored string")]
87 ExportPublicKeyToArmoredStringError(#[source] pgp::native::errors::Error),
88 #[error("cannot write secret key file at {1}")]
89 WriteSecretKeyFileError(#[source] io::Error, PathBuf),
90 #[error("cannot write public key file at {1}")]
91 WritePublicKeyFileError(#[source] io::Error, PathBuf),
92 #[cfg(feature = "pgp-native")]
93 #[error("cannot get public key from keyring")]
94 GetPublicKeyFromKeyringError(#[source] keyring::Error),
95 #[cfg(feature = "pgp-native")]
96 #[error("cannot set secret key to keyring")]
97 SetSecretKeyToKeyringError(#[source] keyring::Error),
98 #[cfg(feature = "pgp-native")]
99 #[error("cannot set public key to keyring")]
100 SetPublicKeyToKeyringError(#[source] keyring::Error),
101 #[cfg(feature = "pgp-native")]
102 #[error("cannot get secret key password")]
103 GetPgpSecretKeyPasswdError(#[source] io::Error),
104 #[cfg(feature = "pgp-native")]
105 #[error("cannot create keyring entry from key: {0}")]
106 KeyringError(#[from] keyring::Error),
107 #[error("cannot find any MX record at {0}")]
108 GetMxRecordNotFoundError(String),
109 #[error("cannot find any mailconf TXT record at {0}")]
110 GetMailconfTxtRecordNotFoundError(String),
111 #[error("cannot find any SRV record at {0}")]
112 GetSrvRecordNotFoundError(String),
113 #[cfg(feature = "autoconfig")]
114 #[error("cannot do txt lookup: {0}")]
115 TXTLookUpFailure(#[source] hickory_resolver::error::ResolveError),
116 #[cfg(feature = "autoconfig")]
117 #[error("cannot do mx lookup: {0}")]
118 MXLookUpFailure(#[source] hickory_resolver::error::ResolveError),
119 #[cfg(feature = "autoconfig")]
120 #[error("cannot do srv lookup: {0}")]
121 SRVLookUpFailure(#[source] hickory_resolver::error::ResolveError),
122 #[cfg(feature = "autoconfig")]
123 #[error("cannot get autoconfig from {0}: {1}")]
124 GetAutoConfigError(Uri, StatusCode),
125 #[cfg(feature = "autoconfig")]
126 #[error("cannot do a get request for autoconfig from {0}: {1}")]
127 GetConnectionAutoConfigError(Uri, #[source] http::Error),
128 #[cfg(feature = "autoconfig")]
129 #[error("cannot get the body of response for autoconfig from {0}: {1}")]
130 ToBytesAutoConfigError(Uri, #[source] http::Error),
131 #[cfg(feature = "autoconfig")]
132 #[error("cannot decode the body of response for autoconfig from {0}: {1}")]
133 SerdeXmlFailedForAutoConfig(Uri, #[source] serde_xml_rs::Error),
134 #[cfg(feature = "autoconfig")]
135 #[error("cannot parse email {0}: {1}")]
136 ParsingEmailAddress(String, #[source] email_address::Error),
137}