Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(email-db-client): Better logging (#1929)

Evan Hutnik68c95f4ef03f
diff --git a/rust/cloud-storage/email_db_client/src/messages/get.rs b/rust/cloud-storage/email_db_client/src/messages/get.rs
index 4fd0548a7d..3e04f4ceba 100644
--- a/rust/cloud-storage/email_db_client/src/messages/get.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/get.rs
@@ -4,7 +4,7 @@ use crate::labels::get;
use crate::parse::db_to_service;
use crate::parse::db_to_service::map_attachmentless_db_message_to_service;
use crate::{attachments, contacts, labels, messages};
-use anyhow::Context;
+
use futures::future::try_join_all;
use models_email::email::db;
use models_email::email::service::message::Message;
@@ -495,7 +495,5 @@ pub async fn convert_db_messages_to_service_concurrent(
}
});
- try_join_all(message_processing_futures)
- .await
- .context("Failed processing messages concurrently")
+ try_join_all(message_processing_futures).await
}
diff --git a/rust/cloud-storage/email_db_client/src/messages/get_parsed.rs b/rust/cloud-storage/email_db_client/src/messages/get_parsed.rs
index ad8ffd567e..66c687969b 100644
--- a/rust/cloud-storage/email_db_client/src/messages/get_parsed.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/get_parsed.rs
@@ -1,6 +1,6 @@
use crate::parse::db_to_service::{self};
use crate::{contacts, labels};
-use anyhow::Context;
+
use futures::future::join_all;
use models_email::email::service::message;
use models_email::email::{db, service};
@@ -46,17 +46,12 @@ pub async fn get_parsed_message_by_id(
let message_ids: Vec<Uuid> = vec![db_message.id];
- let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch senders in bulk")?;
+ let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids).await?;
- let recipients_map = contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ let recipients_map =
+ contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids).await?;
- let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let sender = db_message
.from_contact_id
@@ -111,17 +106,12 @@ pub async fn get_parsed_messages_by_id_batch(
let message_ids: Vec<Uuid> = db_messages.iter().map(|m| m.id).collect();
- let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch senders in bulk")?;
+ let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids).await?;
- let recipients_map = contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ let recipients_map =
+ contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids).await?;
- let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let tasks: Vec<_> = db_messages
.into_iter()
@@ -212,17 +202,12 @@ pub async fn get_paginated_parsed_messages_by_thread_id(
let message_ids: Vec<Uuid> = db_messages.iter().map(|m| m.id).collect();
- let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch senders in bulk")?;
+ let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids).await?;
- let recipients_map = contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ let recipients_map =
+ contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids).await?;
- let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let tasks: Vec<_> = db_messages
.into_iter()
diff --git a/rust/cloud-storage/email_db_client/src/messages/get_parsed_search.rs b/rust/cloud-storage/email_db_client/src/messages/get_parsed_search.rs
index 5e514bbac8..24fc446149 100644
--- a/rust/cloud-storage/email_db_client/src/messages/get_parsed_search.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/get_parsed_search.rs
@@ -1,6 +1,6 @@
use crate::parse::db_to_service;
use crate::{contacts, labels};
-use anyhow::Context;
+
use futures::future::join_all;
use models_email::db;
use models_email::service::message;
@@ -46,17 +46,12 @@ pub async fn get_parsed_search_message_by_id(
let message_ids: Vec<Uuid> = vec![db_message.id];
- let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch senders in bulk")?;
+ let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids).await?;
- let recipients_map = contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ let recipients_map =
+ contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids).await?;
- let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let sender = db_message
.from_contact_id
@@ -137,17 +132,12 @@ pub async fn get_paginated_parsed_search_messages_by_thread_id(
let message_ids: Vec<Uuid> = db_messages.iter().map(|m| m.id).collect();
- let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch senders in bulk")?;
+ let senders_map = contacts::get::get_senders_contacts_map(&mut *conn, &message_ids).await?;
- let recipients_map = contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ let recipients_map =
+ contacts::get::fetch_db_recipients_in_bulk(&mut *conn, &message_ids).await?;
- let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = labels::get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let tasks: Vec<_> = db_messages
.into_iter()
diff --git a/rust/cloud-storage/email_db_client/src/messages/insert.rs b/rust/cloud-storage/email_db_client/src/messages/insert.rs
index 57bb0c43a5..ce1b5c88a2 100644
--- a/rust/cloud-storage/email_db_client/src/messages/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/insert.rs
@@ -2,7 +2,7 @@ use crate::attachments::provider;
use crate::messages::replying_to_id;
use crate::parse::service_to_db::addresses_from_message;
use crate::{contacts, labels, parse, threads};
-use anyhow::Context;
+
use models_email::email::db::address::UpsertedRecipients;
use models_email::email::service::message;
use sqlx::PgPool;
@@ -29,12 +29,9 @@ pub async fn insert_message_with_tx(
recipents.from_contact_id,
update_thread_metadata,
)
- .await
- .context("Failed to insert message")?;
+ .await?;
- contacts::upsert_message::upsert_message_recipients(tx, message_db_id, &recipents)
- .await
- .context("Failed to insert recipients")?;
+ contacts::upsert_message::upsert_message_recipients(tx, message_db_id, &recipents).await?;
if !message.labels.is_empty() {
let provider_label_ids: Vec<String> = message
@@ -49,20 +46,15 @@ pub async fn insert_message_with_tx(
&provider_label_ids,
true,
)
- .await
- .context("failed to upsert labels")?;
+ .await?;
}
if !message.attachments.is_empty() {
- provider::insert_attachments(tx, message_db_id, &mut message.attachments)
- .await
- .context("Failed to insert attachments")?;
+ provider::insert_attachments(tx, message_db_id, &mut message.attachments).await?;
}
if update_thread_metadata {
- threads::update::update_thread_metadata(tx, thread_db_id, link_id)
- .await
- .context("Failed to update thread metadata")?;
+ threads::update::update_thread_metadata(tx, thread_db_id, link_id).await?;
replying_to_id::update_message_replying_to_from_headers(
tx,
@@ -70,8 +62,7 @@ pub async fn insert_message_with_tx(
message_db_id,
link_id,
)
- .await
- .context("Failed to update message replying_to_id from headers")?;
+ .await?;
}
Ok(())
@@ -165,8 +156,7 @@ pub async fn insert_message(
let recipients =
contacts::upsert_message::parse_and_upsert_message_contacts(pool, link_id, addresses)
- .await
- .context("Failed to insert address ids")?;
+ .await?;
let mut tx = pool.begin().await?;
@@ -186,12 +176,10 @@ pub async fn insert_message(
}
Err(e) => {
if let Err(rollback_err) = tx.rollback().await {
- return Err(e)
- .context("Failed to insert message")
- .context(format!("Rollback also failed: {:?}", rollback_err));
+ return Err(e.context(format!("Rollback also failed: {:?}", rollback_err)));
}
- Err(e).context("Failed to insert message")
+ Err(e)
}
}
}
diff --git a/rust/cloud-storage/email_db_client/src/messages/replying_to_id.rs b/rust/cloud-storage/email_db_client/src/messages/replying_to_id.rs
index 915622306a..6fb623c320 100644
--- a/rust/cloud-storage/email_db_client/src/messages/replying_to_id.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/replying_to_id.rs
@@ -1,6 +1,6 @@
use crate::messages;
use crate::messages::get;
-use anyhow::Context;
+
use models_email::service::message;
use sqlx::types::Uuid;
use std::collections::HashMap;
@@ -112,27 +112,15 @@ pub async fn update_message_replying_to_from_headers(
if let Some(headers) = &message.headers_json
&& let Some(in_reply_to) = extract_in_reply_to(headers)
{
- let db_id_replying_to = get::get_message_id_by_global_id(&mut *tx, link_id, &in_reply_to)
- .await
- .with_context(|| {
- format!(
- "Failed to get message id for global id {} for link id {}",
- in_reply_to, link_id,
- )
- })?;
+ let db_id_replying_to =
+ get::get_message_id_by_global_id(&mut *tx, link_id, &in_reply_to).await?;
// doesn't always exist, because forwarded emails can have In-Reply-To referring to
// the email that was forwarded, which may or may not exist in db
if let Some(db_id_replying_to) = db_id_replying_to {
// Update the message's replying_to_id field
update_db_message_replying_to_id(tx, link_id, message_db_id, Some(db_id_replying_to))
- .await
- .with_context(|| {
- format!(
- "Failed to update replying_to_id for message {} to {}",
- message_db_id, db_id_replying_to
- )
- })?;
+ .await?;
tracing::debug!(
message_id = %message_db_id,
@@ -159,13 +147,7 @@ pub async fn update_thread_messages_replying_to(
thread_db_id,
link_id,
)
- .await
- .with_context(|| {
- format!(
- "Failed to get simple messages for thread id {} for link id {}",
- thread_db_id, link_id
- )
- })?;
+ .await?;
// if there is only one message in the thread, we know it isn't replying to anything
if simple_messages.len() == 1 {
diff --git a/rust/cloud-storage/email_db_client/src/threads/insert.rs b/rust/cloud-storage/email_db_client/src/threads/insert.rs
index b2e1488e9e..7ca666ac3f 100644
--- a/rust/cloud-storage/email_db_client/src/threads/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/insert.rs
@@ -1,7 +1,7 @@
use crate::messages::replying_to_id::update_thread_messages_replying_to;
use crate::parse::service_to_db::addresses_from_message;
use crate::{contacts, messages, parse};
-use anyhow::Context;
+
use models_email::email::db::address::UpsertedRecipients;
use models_email::email::service::thread;
use sqlx::types::Uuid;
@@ -32,8 +32,7 @@ pub async fn insert_thread_and_messages(
let recipients =
contacts::upsert_message::parse_and_upsert_message_contacts(pool, link_id, addresses)
- .await
- .context("Failed to insert address ids")?;
+ .await?;
// can't be null bc we are getting the message from gmail api directly
recipient_map.insert(message.provider_id.clone().unwrap(), recipients);
@@ -43,9 +42,7 @@ pub async fn insert_thread_and_messages(
let result = async {
// Insert thread
- let thread_id = insert_thread(&mut *tx, &service_thread, link_id)
- .await
- .context("Failed to insert thread")?;
+ let thread_id = insert_thread(&mut *tx, &service_thread, link_id).await?;
// Insert all messages
for mut message in service_thread.messages.clone() {
@@ -59,17 +56,14 @@ pub async fn insert_thread_and_messages(
recipient_map.remove(provider_id).unwrap(),
false,
)
- .await
- .context("Failed to insert message")?;
+ .await?;
}
// Now that messages have been inserted, we can set replying_to_ids of messages for threads
// with more than one message. If a thread only has one message, we know it will have no
// messages replying to other messages and thus no replying_to_ids.
if service_thread.messages.len() > 1 {
- update_thread_messages_replying_to(&mut tx, thread_id, link_id)
- .await
- .context("Failed to update messages replying_to_ids")?;
+ update_thread_messages_replying_to(&mut tx, thread_id, link_id).await?;
}
Ok(thread_id)
diff --git a/rust/cloud-storage/email_db_client/src/threads/update.rs b/rust/cloud-storage/email_db_client/src/threads/update.rs
index a3175633f8..2a1348df46 100644
--- a/rust/cloud-storage/email_db_client/src/threads/update.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/update.rs
@@ -1,5 +1,5 @@
use crate::messages::get::fetch_messages_metadata;
-use anyhow::Context;
+
use chrono::{DateTime, Utc};
use models_email::email::service::message::{is_inbound, is_outbound, is_spam_or_trash};
use models_email::service;
@@ -140,9 +140,7 @@ pub async fn update_thread_metadata(
thread_db_id: Uuid,
link_id: Uuid,
) -> anyhow::Result<()> {
- let messages = fetch_messages_metadata(&mut *tx, thread_db_id)
- .await
- .context("Failed to get messages for thread")?;
+ let messages = fetch_messages_metadata(&mut *tx, thread_db_id).await?;
// if any non-sent message in the thread has the INBOX label, the thread is visible in the inbox
let inbox_visible = messages.iter().any(|message| {
@@ -206,8 +204,7 @@ pub async fn update_thread_metadata(
latest_outbound_message_ts,
latest_non_spam_message_ts,
)
- .await
- .context("Failed to update thread timestamps")?;
+ .await?;
Ok(())
}