Skip to content

Commit

Permalink
Adding error context for forward_msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Oct 20, 2024
1 parent deb1460 commit 2e030aa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4142,7 +4142,9 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId)
chat_id
.unarchive_if_not_muted(context, MessageState::Undefined)
.await?;
let mut chat = Chat::load_from_db(context, chat_id).await?;
let mut chat = Chat::load_from_db(context, chat_id)
.await
.context("Failed to load chat from the database")?;
if let Some(reason) = chat.why_cant_send(context).await? {
bail!("cannot send to {}: {}", chat_id, reason);
}
Expand All @@ -4158,7 +4160,8 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId)
|row| row.get::<_, MsgId>(0),
|ids| ids.collect::<Result<Vec<_>, _>>().map_err(Into::into),
)
.await?;
.await
.context("Failed to sort forwarded messages by timestamp")?;

for id in ids {
let src_msg_id: MsgId = id;
Expand Down Expand Up @@ -4213,9 +4216,14 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId)
msg.state = MessageState::OutPending;
new_msg_id = chat
.prepare_msg_raw(context, &mut msg, None, curr_timestamp)
.await?;
.await
.context("Failed to prepare forwarded message")?;
curr_timestamp += 1;
if !create_send_msg_jobs(context, &mut msg).await?.is_empty() {
if !create_send_msg_jobs(context, &mut msg)
.await
.context("Failed to create send jobs for the forwarded message")?
.is_empty()
{
context.scheduler.interrupt_smtp().await;
}
}
Expand Down

0 comments on commit 2e030aa

Please sign in to comment.