email/smtp/
error.rs

1use std::{any::Any, result};
2
3use thiserror::Error;
4
5use crate::{AnyBoxedError, AnyError};
6
7/// The global `Result` alias of the module.
8pub type Result<T> = result::Result<T, Error>;
9
10/// The global `Error` enum of the module.
11#[derive(Debug, Error)]
12pub enum Error {
13    #[error("cannot send message without a sender")]
14    SendMessageMissingSenderError,
15    #[error("cannot send message without a recipient")]
16    SendMessageMissingRecipientError,
17    #[error("cannot send message: request timed out")]
18    SendMessageTimedOutError,
19    #[error("cannot send message")]
20    SendMessageError(#[source] mail_send::Error),
21    #[error("cannot connect to smtp server using tcp")]
22    ConnectTcpSmtpError(#[source] mail_send::Error),
23    #[error("cannot connect to smtp server using tls")]
24    ConnectTlsSmtpError(#[source] mail_send::Error),
25    #[error("cannot get smtp password")]
26    GetPasswdSmtpError(#[source] secret::Error),
27    #[error("cannot get smtp password: password is empty")]
28    GetPasswdEmptySmtpError,
29    #[error("cannot get access token")]
30    AccessTokenWasNotAvailable,
31    #[error("cannot refresh access token")]
32    RefreshingAccessTokenFailed,
33    #[error("resetting oauth failed")]
34    ResettingOAuthFailed,
35    #[error("configuring oauth failed")]
36    ConfiguringOAuthFailed,
37    #[error("replacing keyring failed: {0}")]
38    ReplacingKeyringFailed(#[source] secret::Error),
39    #[error("mail send noop failed: {0}")]
40    MailSendNoOpFailed(#[source] mail_send::Error),
41}
42
43impl AnyError for Error {
44    fn as_any(&self) -> &dyn Any {
45        self
46    }
47}
48
49impl From<Error> for AnyBoxedError {
50    fn from(err: Error) -> Self {
51        Box::new(err)
52    }
53}