Skip to content

Commit 18e098e

Browse files
committed
simpler error type
1 parent 3f3d95e commit 18e098e

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

‎src/smtp.rs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ async fn smtp_send(
263263
smtp.last_send_error = send_result.as_ref().err().map(|e| e.to_string());
264264

265265
let status = match send_result {
266-
Err(crate::smtp::send::Error::SmtpSend(err)) => {
266+
Err(send::Error::SmtpSend(err)) => {
267267
// Remote error, retry later.
268268
info!(context, "SMTP failed to send: {:?}.", &err);
269269

@@ -345,13 +345,7 @@ async fn smtp_send(
345345

346346
res
347347
}
348-
Err(crate::smtp::send::Error::Envelope(err)) => {
349-
// Local error, job is invalid, do not retry.
350-
smtp.disconnect();
351-
warn!(context, "SMTP job is invalid: {err:#}.");
352-
SendResult::Failure(err)
353-
}
354-
Err(crate::smtp::send::Error::Other(err)) => {
348+
Err(send::Error::Other(err)) => {
355349
// Local error, job is invalid, do not retry.
356350
smtp.disconnect();
357351
warn!(context, "Unable to load SMTP job: {err:#}.");

‎src/smtp/send.rs‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! # SMTP message sending
22
3+
use anyhow::Context as _;
34
use async_smtp::{EmailAddress, Envelope, SendableEmail};
45

56
use super::Connection;
@@ -11,8 +12,6 @@ pub type Result<T> = std::result::Result<T, Error>;
1112

1213
#[derive(Debug, thiserror::Error)]
1314
pub enum Error {
14-
#[error("Envelope error: {}", _0)]
15-
Envelope(anyhow::Error),
1615
#[error("Send error: {}", _0)]
1716
SmtpSend(async_smtp::error::Error),
1817
#[error("{}", _0)]
@@ -35,8 +34,8 @@ impl Connection {
3534
context.ratelimit.write().await.send();
3635
}
3736

38-
let envelope =
39-
Envelope::new(Some(self.from.clone()), recipients.to_vec()).map_err(Error::Envelope)?;
37+
let envelope = Envelope::new(Some(self.from.clone()), recipients.to_vec())
38+
.context("Envelope error")?;
4039
let mail = SendableEmail::new(envelope, message);
4140

4241
self.transport.send(mail).await.map_err(Error::SmtpSend)?;

0 commit comments

Comments
 (0)