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): Improve logging in db client (#1555)

Evan Hutnikd3ff6a864db8
diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-59703c07f7d64f1f958f7255a0924c5b15e327756371063442762797bc3e42f3.json b/rust/cloud-storage/email_db_client/.sqlx/query-8ad8fb713125453e2416a6a4992c01f32d29696d130e0e1f46599273575bcb02.json
similarity index 75%
rename from rust/cloud-storage/email_db_client/.sqlx/query-59703c07f7d64f1f958f7255a0924c5b15e327756371063442762797bc3e42f3.json
rename to rust/cloud-storage/email_db_client/.sqlx/query-8ad8fb713125453e2416a6a4992c01f32d29696d130e0e1f46599273575bcb02.json
index 1d8feb186c..f697fc82ae 100644
--- a/rust/cloud-storage/email_db_client/.sqlx/query-59703c07f7d64f1f958f7255a0924c5b15e327756371063442762797bc3e42f3.json
+++ b/rust/cloud-storage/email_db_client/.sqlx/query-8ad8fb713125453e2416a6a4992c01f32d29696d130e0e1f46599273575bcb02.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT \n l.id, \n l.link_id, \n l.provider_label_id, \n l.name, \n l.created_at,\n l.message_list_visibility as \"message_list_visibility: _\",\n l.label_list_visibility as \"label_list_visibility: _\",\n l.type as \"type_: _\"\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = $1\n ORDER BY l.name\n ",
+ "query": "\n SELECT\n l.id,\n l.link_id,\n l.provider_label_id,\n l.name,\n l.created_at,\n l.message_list_visibility as \"message_list_visibility: _\",\n l.label_list_visibility as \"label_list_visibility: _\",\n l.type as \"type_: _\"\n FROM email_message_labels ml\n JOIN email_labels l ON ml.label_id = l.id\n WHERE ml.message_id = $1\n ORDER BY l.name\n ",
"describe": {
"columns": [
{
@@ -91,5 +91,5 @@
false
]
},
- "hash": "59703c07f7d64f1f958f7255a0924c5b15e327756371063442762797bc3e42f3"
+ "hash": "8ad8fb713125453e2416a6a4992c01f32d29696d130e0e1f46599273575bcb02"
}
diff --git a/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs b/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs
index 4cdc632778..5405b8e9ce 100644
--- a/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/attachments/provider/mod.rs
@@ -5,7 +5,6 @@ pub mod upload_filters;
use crate::parse::db_to_service::map_db_attachment_to_service;
use crate::parse::service_to_db::map_service_attachments_to_db;
-use anyhow::Context;
use models_email::db::attachment;
use models_email::{db, service};
use sqlx::types::Uuid;
@@ -33,12 +32,7 @@ pub async fn insert_attachments(
WHERE message_id = $1
"#,
message_id
- ).fetch_all(&mut *tx).await.with_context(|| {
- format!(
- "Failed to fetch attachments for message_id {}",
- message_id
- )
- })?;
+ ).fetch_all(&mut *tx).await?;
// Filter to find attachments that exist in the database but don't match any in db_attachments.
// we compare using filename, mime_type, size_bytes, and content_id as we don't get a concrete ID from gmail that
@@ -86,13 +80,7 @@ pub async fn insert_attachments(
&orphaned_ids
)
.execute(&mut *tx)
- .await
- .with_context(|| {
- format!(
- "Failed to delete orphaned attachments with ids {:?} for message_id {}",
- orphaned_ids, message_id
- )
- })?;
+ .await?;
}
if new_attachments.is_empty() {
@@ -145,13 +133,7 @@ pub async fn insert_attachments(
.bind(&size_bytes_vec)
.bind(&content_ids)
.execute(&mut *tx)
- .await
- .with_context(|| {
- format!(
- "Failed to batch insert/update attachment metadata for message_id {} and provider_attachment_ids {:?}",
- message_id, provider_attachment_ids
- )
- })?;
+ .await?;
Ok(())
}
@@ -178,8 +160,7 @@ pub async fn fetch_db_attachments_in_bulk(
message_ids
)
.fetch_all(pool)
- .await
- .context("Failed to fetch attachments in bulk")?;
+ .await?;
let mut attachments_map: HashMap<Uuid, Vec<attachment::Attachment>> = HashMap::new();
for attachment in results {
@@ -203,8 +184,7 @@ where
message_id
)
.execute(executor)
- .await
- .with_context(|| format!("Failed to delete attachments for message_id {}", message_id))?;
+ .await?;
Ok(())
}
@@ -231,13 +211,7 @@ pub async fn fetch_attachment_by_id(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch attachment with id {} for link_id {}",
- attachment_id, link_id
- )
- })?;
+ .await?;
match result {
Some(record) => {
@@ -300,8 +274,7 @@ pub async fn get_attachments_by_thread_ids(
thread_ids
)
.fetch_all(db)
- .await
- .context("Failed to fetch attachments for threads")?;
+ .await?;
// Group attachments by thread_id
let mut result: HashMap<Uuid, Vec<service::attachment::Attachment>> = HashMap::new();
@@ -398,8 +371,7 @@ pub async fn get_thread_id_for_attachment(
attachment_id,
)
.fetch_optional(db)
- .await
- .with_context(|| format!("Failed to fetch thread_id for attachment {}", attachment_id))?;
+ .await?;
Ok(result.map(|record| (record.thread_id, record.link_id)))
}
diff --git a/rust/cloud-storage/email_db_client/src/backfill/job/get.rs b/rust/cloud-storage/email_db_client/src/backfill/job/get.rs
index 123d5898b8..580123b94d 100644
--- a/rust/cloud-storage/email_db_client/src/backfill/job/get.rs
+++ b/rust/cloud-storage/email_db_client/src/backfill/job/get.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use models_email::email::db;
use models_email::email::service;
use sqlx::PgPool;
@@ -28,8 +27,7 @@ pub async fn get_backfill_job(
job_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to query backfill job with ID: {}", job_id))?;
+ .await?;
Ok(record.map(Into::into))
}
@@ -61,8 +59,7 @@ pub async fn get_backfill_job_with_link_id(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to query backfill job with ID: {}", job_id))?;
+ .await?;
Ok(record.map(Into::into))
}
@@ -91,8 +88,7 @@ pub async fn get_active_backfill_job(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| "Failed to query for active backfill job".to_string())?;
+ .await?;
Ok(record.map(Into::into))
}
@@ -125,13 +121,7 @@ pub async fn get_recent_jobs_by_fusionauth_user_id(
fusionauth_user_id
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch recent backfill jobs for fusionauth_user_id: {}",
- fusionauth_user_id
- )
- })?;
+ .await?;
// Convert all database records to service models
let jobs = records.into_iter().map(Into::into).collect();
diff --git a/rust/cloud-storage/email_db_client/src/backfill/job/insert.rs b/rust/cloud-storage/email_db_client/src/backfill/job/insert.rs
index 35b2605a21..f2d56bf0f8 100644
--- a/rust/cloud-storage/email_db_client/src/backfill/job/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/backfill/job/insert.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use models_email::email::db;
use models_email::email::service;
use sqlx::PgPool;
@@ -35,13 +34,7 @@ pub async fn create_backfill_job(
num_threads
)
.fetch_one(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to create backfill job for link_id {} with num_threads {:?}",
- link_id, num_threads
- )
- })?;
+ .await?;
Ok(record.into())
}
diff --git a/rust/cloud-storage/email_db_client/src/backfill/job/update.rs b/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
index e48dd34be7..ec34c217b1 100644
--- a/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
+++ b/rust/cloud-storage/email_db_client/src/backfill/job/update.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use models_email::email::db;
use models_email::email::service;
use sqlx::PgPool;
@@ -24,8 +23,7 @@ where
job_id
)
.execute(executor)
- .await
- .with_context(|| format!("Failed to update status for backfill job {}", job_id))?;
+ .await?;
if result.rows_affected() == 0 {
return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
@@ -49,13 +47,7 @@ pub async fn cancel_active_jobs_by_link_id(pool: &PgPool, link_id: Uuid) -> anyh
link_id
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to update status for backfill jobs with link_id: {}",
- link_id
- )
- })?;
+ .await?;
let rows_affected = result.rows_affected() as usize;
Ok(rows_affected)
@@ -77,8 +69,7 @@ pub async fn update_job_total_threads(
job_id
)
.execute(pool)
- .await
- .with_context(|| format!("Failed to update num_threads for backfill job {}", job_id))?;
+ .await?;
if result.rows_affected() == 0 {
return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
@@ -103,13 +94,7 @@ pub async fn update_job_threads_retrieved_count(
job_id
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to update threads_retrieved_count for backfill job {}",
- job_id
- )
- })?;
+ .await?;
if result.rows_affected() == 0 {
return Err(anyhow::anyhow!("No backfill job found with ID: {}", job_id));
diff --git a/rust/cloud-storage/email_db_client/src/contacts/delete.rs b/rust/cloud-storage/email_db_client/src/contacts/delete.rs
index eb24369f9e..a1185c594c 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/delete.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use sqlx::types::Uuid;
use sqlx::{Executor, Postgres};
@@ -13,8 +12,7 @@ where
message_id
)
.execute(executor)
- .await
- .with_context(|| format!("Failed to delete recipients for message_id {}", message_id))?;
+ .await?;
let deleted_count = result.rows_affected();
diff --git a/rust/cloud-storage/email_db_client/src/contacts/get.rs b/rust/cloud-storage/email_db_client/src/contacts/get.rs
index 280ab4df64..423f7b45c9 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/get.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/get.rs
@@ -2,7 +2,6 @@
mod test;
use crate::parse::db_to_service::map_db_contact_to_service;
-use anyhow::Context;
use chrono::{DateTime, Utc};
use email_utils::{dedupe_emails, is_generic_email};
use models_email::service::address;
@@ -120,7 +119,7 @@ pub async fn fetch_db_recipients(
})
.fetch_all(pool)
.await
- .context("Failed to fetch recipients")
+ .map_err(Into::into)
}
/// Fetches all recipients for a given list of message IDs in a single query
@@ -160,8 +159,7 @@ where
message_ids
)
.fetch_all(executor)
- .await
- .context("Failed to fetch recipients in bulk")?;
+ .await?;
let mut recipients_map = HashMap::new();
for row in results {
@@ -203,12 +201,7 @@ pub async fn fetch_id_by_email(
)
.fetch_optional(pool)
.await
- .with_context(|| {
- format!(
- "Failed to fetch contact ID for email address {}",
- email_address
- )
- })
+ .map_err(Into::into)
}
/// Fetch contact for a given email address
@@ -229,13 +222,7 @@ pub async fn fetch_contact_by_email(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch contact for email address {}",
- email_address
- )
- })?;
+ .await?;
Ok(contact.and_then(|c| map_db_contact_to_service(Some(c))))
}
@@ -295,12 +282,7 @@ where
)
.fetch_all(executor)
.await
- .with_context(|| {
- format!(
- "Failed to fetch email addresses with IDs: {:?}",
- unique_ids_vec
- )
- })
+ .map_err(Into::into)
}
/// Fetches sender contacts for multiple messages and returns a map keyed by message_id
@@ -350,8 +332,7 @@ where
message_ids
)
.fetch_all(executor)
- .await
- .context("Failed to fetch senders by message IDs")?;
+ .await?;
let mut senders_map = HashMap::new();
for row in results {
@@ -403,8 +384,7 @@ pub async fn fetch_contacts_by_thread_ids(
thread_ids
)
.fetch_all(pool)
- .await
- .context("Failed to fetch contacts by thread IDs")?;
+ .await?;
let mut result: ThreadContactsMap = HashMap::new();
for row in rows {
@@ -476,8 +456,7 @@ pub async fn fetch_contacts_by_link_id(
link_id
)
.fetch_all(pool)
- .await
- .context("Failed to fetch contacts for link ID")?;
+ .await?;
Ok(db_contacts.into_iter().map(Into::into).collect())
}
@@ -508,8 +487,7 @@ pub async fn fetch_contacts_emails_by_link_id(
link_id
)
.fetch_all(pool)
- .await
- .context("Failed to fetch contacts for link ID")?;
+ .await?;
let deduped = dedupe_emails(rows.into_iter().map(|row| row.email_address).collect());
Ok(deduped
diff --git a/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs b/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
index d8980ecca7..018be21f45 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/upsert_message.rs
@@ -2,7 +2,6 @@
mod tests;
use crate::contacts::normalize;
-use anyhow::Context;
use models_email::db;
use models_email::db::contact::ContactPhotoless;
use models_email::db::{address, message};
@@ -85,7 +84,7 @@ pub async fn parse_and_upsert_message_contacts(
results.recipients = db_recipients;
}
Err(e) => {
- return Err(e).context("Failed during batch upsert of email addresses");
+ return Err(e);
}
}
@@ -296,12 +295,8 @@ pub async fn upsert_message_recipients(
&contact_ids_to_insert,
&recipient_types_to_insert as &[db::address::EmailRecipientType]
)
- .execute(&mut *tx)
- .await
- .with_context(|| format!(
- "Failed to delete old message recipients. message_id: {}, contact_ids_to_insert: {:?}, recipient_types_to_insert: {:?}",
- message_id, contact_ids_to_insert, recipient_types_to_insert
- ))?;
+ .execute(&mut *tx)
+ .await?;
sqlx::query!(
r#"
@@ -314,12 +309,8 @@ pub async fn upsert_message_recipients(
&names_to_insert as &[Option<String>],
&recipient_types_to_insert as &[db::address::EmailRecipientType]
)
- .execute(&mut *tx)
- .await
- .with_context(|| format!(
- "Failed to batch insert message recipients. message_ids_to_insert: {:?}, contact_ids_to_insert: {:?}, recipient_types_to_insert: {:?}",
- message_ids_to_insert, contact_ids_to_insert, recipient_types_to_insert
- ))?;
+ .execute(&mut *tx)
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_db_client/src/contacts/upsert_sync.rs b/rust/cloud-storage/email_db_client/src/contacts/upsert_sync.rs
index 68568913a4..ec40b6c676 100644
--- a/rust/cloud-storage/email_db_client/src/contacts/upsert_sync.rs
+++ b/rust/cloud-storage/email_db_client/src/contacts/upsert_sync.rs
@@ -1,9 +1,7 @@
use crate::parse::service_to_db::map_new_contact_to_db;
-use anyhow::Context;
use models_email::db;
use models_email::service::contact::Contact;
use sqlx::PgPool;
-use sqlx::types::Uuid;
/// Upsert methods used by contact sync process, triggered by initial backfill and daily cron.
/// Upserts multiple contacts into the contacts table
@@ -62,15 +60,7 @@ pub async fn upsert_contacts(pool: &PgPool, contacts: &[Contact]) -> anyhow::Res
&sfs_photo_urls as &[Option<String>]
)
.execute(pool)
-.await
-.with_context(|| {
- format!(
- "Failed to insert {} contacts for link_id {}",
- link_ids.len(),
- // all contacts should have the same link_id
- link_ids.first().unwrap_or(&Uuid::default())
- )
-})?;
+.await?;
Ok(result.rows_affected())
}
diff --git a/rust/cloud-storage/email_db_client/src/histories/mod.rs b/rust/cloud-storage/email_db_client/src/histories/mod.rs
index b5adb3744f..f314e03951 100644
--- a/rust/cloud-storage/email_db_client/src/histories/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/histories/mod.rs
@@ -1,4 +1,4 @@
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use doppleganger::Mirror;
use models_email::gmail::history::{GmailHistory, GmailHistoryDb};
use sqlx::PgPool;
@@ -30,14 +30,7 @@ pub async fn fetch_history_id_for_link(
db_provider as _
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch history_id for email {} and provider {}",
- email_address,
- db_provider.as_str()
- )
- })?;
+ .await?;
// Extract the history_id field from the result
Ok(result.map(|r| r.history_id))
@@ -71,13 +64,7 @@ pub async fn upsert_gmail_history(
db_history.history_id
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to upsert gmail_history for link_id {} with history_id {}",
- db_history.link_id, db_history.history_id
- )
- })?;
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_db_client/src/labels/delete.rs b/rust/cloud-storage/email_db_client/src/labels/delete.rs
index d73bcea39d..257e621dd7 100644
--- a/rust/cloud-storage/email_db_client/src/labels/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/delete.rs
@@ -1,4 +1,4 @@
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use sqlx::types::Uuid;
use sqlx::{Executor, PgPool, Postgres};
@@ -36,14 +36,8 @@ where
link_id,
provider_label_id
)
- .execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to delete message_labels for {} messages with provider_label_id {} and link_id {}",
- message_ids.len(), provider_label_id, link_id
- )
- })?;
+ .execute(executor)
+ .await?;
let rows_affected = result.rows_affected() as usize;
@@ -64,13 +58,7 @@ where
message_id
)
.execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to delete message_labels for message_id {}",
- message_id
- )
- })?;
+ .await?;
Ok(())
}
@@ -100,14 +88,8 @@ pub async fn delete_db_message_labels(
link_id,
&provider_label_ids
)
- .execute(tx)
- .await
- .with_context(|| {
- format!(
- "Failed to delete message_labels for message_id {} with provider_label_ids {:?} and link_id {}",
- message_id, provider_label_ids, link_id
- )
- })?;
+ .execute(tx)
+ .await?;
Ok(())
}
@@ -134,12 +116,8 @@ pub async fn delete_labels_by_provider_ids(
link_id,
&provider_label_ids
)
- .execute(pool)
- .await
- .with_context(|| format!(
- "Failed to delete message_labels referencing labels with link_id {} and provider_label_ids {:?}",
- link_id, provider_label_ids
- ))?;
+ .execute(pool)
+ .await?;
tracing::debug!(
link_id = %link_id,
@@ -158,13 +136,7 @@ pub async fn delete_labels_by_provider_ids(
&provider_label_ids
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to delete labels with link_id {} and provider_label_ids {:?}",
- link_id, provider_label_ids
- )
- })?;
+ .await?;
let rows_affected = result.rows_affected();
@@ -178,10 +150,7 @@ pub async fn delete_label_by_id(
link_id: Uuid,
) -> anyhow::Result<bool> {
// Begin a transaction since we need to delete from multiple tables
- let mut tx = pool
- .begin()
- .await
- .context("Failed to begin transaction for label deletion")?;
+ let mut tx = pool.begin().await?;
// First, delete any message_labels entries that reference this label to avoid foreign key issues
let deleted_message_labels = sqlx::query!(
@@ -192,13 +161,7 @@ pub async fn delete_label_by_id(
label_id
)
.execute(&mut *tx)
- .await
- .with_context(|| {
- format!(
- "Failed to delete message_labels referencing label with id {} and link_id {}",
- label_id, link_id
- )
- })?;
+ .await?;
tracing::debug!(
label_id = %label_id,
@@ -217,21 +180,13 @@ pub async fn delete_label_by_id(
link_id
)
.execute(&mut *tx)
- .await
- .with_context(|| {
- format!(
- "Failed to delete label with id {} and link_id {}",
- label_id, link_id
- )
- })?;
+ .await?;
let rows_affected = result.rows_affected();
let label_found = rows_affected > 0;
// Commit the transaction
- tx.commit()
- .await
- .context("Failed to commit transaction for label deletion")?;
+ tx.commit().await?;
Ok(label_found)
}
diff --git a/rust/cloud-storage/email_db_client/src/labels/get.rs b/rust/cloud-storage/email_db_client/src/labels/get.rs
index 0721fd1110..cd64d09a79 100644
--- a/rust/cloud-storage/email_db_client/src/labels/get.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/get.rs
@@ -1,7 +1,7 @@
#[cfg(test)]
mod test;
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use models_email::db;
use models_email::email::service::label;
use sqlx::PgPool;
@@ -34,14 +34,8 @@ pub async fn fetch_message_label(
provider_label_id,
link_id
)
- .fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message_label for message_id {} with provider_label_id {} and link_id {}",
- message_id, provider_label_id, link_id
- )
- })?;
+ .fetch_optional(pool)
+ .await?;
Ok(record.map(Into::into))
}
@@ -51,14 +45,14 @@ pub async fn fetch_message_labels(
pool: &PgPool,
message_db_id: Uuid,
) -> anyhow::Result<Vec<db::label::Label>> {
- sqlx::query_as!(
+ let labels = sqlx::query_as!(
db::label::Label,
r#"
- SELECT
- l.id,
- l.link_id,
- l.provider_label_id,
- l.name,
+ SELECT
+ l.id,
+ l.link_id,
+ l.provider_label_id,
+ l.name,
l.created_at,
l.message_list_visibility as "message_list_visibility: _",
l.label_list_visibility as "label_list_visibility: _",
@@ -71,8 +65,9 @@ pub async fn fetch_message_labels(
message_db_id
)
.fetch_all(pool)
- .await
- .context("Failed to fetch labels")
+ .await?;
+
+ Ok(labels)
}
#[tracing::instrument(skip(executor), err)]
@@ -121,8 +116,7 @@ where
message_ids
)
.fetch_all(executor)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ .await?;
let mut labels_map = HashMap::new();
for row in results {
@@ -147,7 +141,7 @@ where
Ok(labels_map)
}
-#[tracing::instrument(skip(pool), level = "debug")]
+#[tracing::instrument(skip(pool), err)]
pub async fn find_missing_provider_labels(
pool: &PgPool,
link_id: Uuid,
@@ -171,13 +165,7 @@ pub async fn find_missing_provider_labels(
&provider_label_ids_vec
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to check for existing labels. link_id: {}, provider_label_ids: {:?}",
- link_id, provider_label_ids_vec
- )
- })?;
+ .await?;
// Create a set of existing provider label IDs for efficient lookup
let existing_provider_label_ids: std::collections::HashSet<String> = existing_labels
@@ -218,8 +206,7 @@ pub async fn fetch_labels_by_link_id(
link_id
)
.fetch_all(pool)
- .await
- .with_context(|| format!("Failed to fetch labels for link_id {}", link_id))?;
+ .await?;
// Convert db::label::Label to service::label::Label
let service_labels: Vec<label::Label> = db_labels.into_iter().map(Into::into).collect();
@@ -252,13 +239,7 @@ pub async fn fetch_label_by_id(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch label with id {} and link_id {}",
- label_id, link_id
- )
- })?;
+ .await?;
// Convert db::label::Label to service::label::Label if found
let service_label = db_label.map(Into::into);
diff --git a/rust/cloud-storage/email_db_client/src/labels/insert.rs b/rust/cloud-storage/email_db_client/src/labels/insert.rs
index bc202935f6..2b0c29c008 100644
--- a/rust/cloud-storage/email_db_client/src/labels/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/labels/insert.rs
@@ -1,4 +1,4 @@
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use models_email::email::{db, service};
use sqlx::types::Uuid;
use sqlx::{Executor, PgPool, Postgres};
@@ -29,14 +29,8 @@ pub async fn insert_message_label(
link_id,
provider_label_id
)
- .fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to add message_label for message_id {} with provider_label_id {} and link_id {}",
- message_id, provider_label_id, link_id
- )
- })?;
+ .fetch_optional(pool)
+ .await?;
// Check if the label was found
match result {
@@ -95,14 +89,8 @@ where
link_id,
provider_label_id
)
- .execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to insert message_labels for {} messages with provider_label_id {} and link_id {}",
- message_ids.len(), provider_label_id, link_id
- )
- })?;
+ .execute(executor)
+ .await?;
let rows_affected = result.rows_affected() as usize;
@@ -208,8 +196,7 @@ pub async fn insert_or_update_labels(
&types as _
)
.execute(pool)
- .await
- .with_context(|| "Failed during batch insert/update of labels".to_string())?;
+ .await?;
Ok(())
}
@@ -265,13 +252,7 @@ pub async fn insert_label(
db_label.type_ as _
)
.fetch_one(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to insert label with provider_label_id {} for link_id {}",
- db_label.provider_label_id, db_label.link_id
- )
- })?;
+ .await?;
let populated_service_label: service::label::Label = inserted_label.into();
@@ -307,11 +288,7 @@ pub async fn insert_message_labels(
&provider_label_ids
)
.fetch_all(&mut *tx)
- .await
- .context(format!(
- "Failed to select label IDs after upsert. link_id: {}, provider_label_ids: {:?}",
- link_id, provider_label_ids
- ))?;
+ .await?;
if label_mappings.len() != provider_label_ids.len() {
return Err(anyhow!(
@@ -330,22 +307,18 @@ pub async fn insert_message_labels(
// upsert and some of the old ones got removed
if delete_old {
sqlx::query!(
- r#"
+ r#"
DELETE FROM email_message_labels
WHERE message_id = $1
AND label_id NOT IN (
SELECT UNNEST($2::uuid[])
)
"#,
- message_id,
- &label_db_ids
- )
- .execute(&mut *tx)
- .await
- .context(format!(
- "Failed to delete message labels for message_id {} where label_id not in label_db_ids {:?}",
- message_id, label_db_ids
- ))?;
+ message_id,
+ &label_db_ids
+ )
+ .execute(&mut *tx)
+ .await?;
}
sqlx::query(
@@ -358,11 +331,7 @@ pub async fn insert_message_labels(
.bind(&message_ids_repeated)
.bind(&label_db_ids)
.execute(&mut *tx)
- .await
- .context(format!(
- "Failed to batch insert message label links. message_id: {}, label_ids: {:?}",
- message_id, label_db_ids
- ))?;
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_db_client/src/links/delete.rs b/rust/cloud-storage/email_db_client/src/links/delete.rs
index 46532c199c..99f129e548 100644
--- a/rust/cloud-storage/email_db_client/src/links/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/links/delete.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use sqlx::PgPool;
use sqlx::types::Uuid;
@@ -15,8 +14,7 @@ pub async fn delete_link_by_id(pool: &PgPool, link_id: Uuid) -> anyhow::Result<u
link_id
)
.execute(pool)
- .await
- .with_context(|| format!("Failed to delete link with ID {}", link_id))?;
+ .await?;
Ok(result.rows_affected())
}
diff --git a/rust/cloud-storage/email_db_client/src/links/get.rs b/rust/cloud-storage/email_db_client/src/links/get.rs
index 655fe2f772..a21e2c4aba 100644
--- a/rust/cloud-storage/email_db_client/src/links/get.rs
+++ b/rust/cloud-storage/email_db_client/src/links/get.rs
@@ -1,4 +1,4 @@
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use doppleganger::Mirror;
use models_email::email::service::link;
use models_email::service;
@@ -8,6 +8,7 @@ use sqlx::types::Uuid;
use crate::links::types::{DbLink, DbUserProvider};
/// fetches a link given an email address and provider.
+#[tracing::instrument(skip(pool), err)]
pub async fn fetch_link_by_email(
pool: &PgPool,
email_address: &str,
@@ -17,8 +18,6 @@ pub async fn fetch_link_by_email(
return Err(anyhow!("Email address cannot be empty"));
}
- let provider_display = provider.as_str();
-
let db_link = sqlx::query_as!(
DbLink,
r#"
@@ -32,13 +31,7 @@ pub async fn fetch_link_by_email(
DbUserProvider::mirror(provider) as _
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch link for email_address {} and provider {}",
- email_address, provider_display
- )
- })?;
+ .await?;
Ok(db_link.map(service::link::Link::try_from).transpose()?)
}
@@ -66,8 +59,7 @@ pub async fn fetch_link_by_macro_id(
macro_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch link for macro_id {}", macro_id))?;
+ .await?;
// Convert DB link to service link if it exists
Ok(db_link.map(service::link::Link::try_from).transpose()?)
@@ -95,13 +87,7 @@ pub async fn fetch_links_by_fusionauth_user_id(
fusionauth_user_id
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch email_links for fusionauth_user_id {}",
- fusionauth_user_id
- )
- })?;
+ .await?;
// Convert DB email_links to service email_links
let service_links: Result<Vec<_>, _> = db_links
@@ -127,8 +113,7 @@ pub async fn fetch_link_by_id(pool: &PgPool, link_id: Uuid) -> anyhow::Result<Op
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch link with ID {}", link_id))?;
+ .await?;
Ok(db_link.map(link::Link::try_from).transpose()?)
}
diff --git a/rust/cloud-storage/email_db_client/src/links/update.rs b/rust/cloud-storage/email_db_client/src/links/update.rs
index d0a8e2901a..60c448ce9d 100644
--- a/rust/cloud-storage/email_db_client/src/links/update.rs
+++ b/rust/cloud-storage/email_db_client/src/links/update.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use sqlx::PgPool;
use sqlx::types::Uuid;
@@ -20,13 +19,7 @@ pub async fn update_link_sync_status(
is_sync_active
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to update sync status to {} for link with ID {}",
- is_sync_active, link_id
- )
- })?;
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_db_client/src/messages/delete.rs b/rust/cloud-storage/email_db_client/src/messages/delete.rs
index 21d3d191c1..c0e58da242 100644
--- a/rust/cloud-storage/email_db_client/src/messages/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/delete.rs
@@ -1,5 +1,4 @@
use crate::threads;
-use anyhow::Context;
use models_email::email::service::message;
use sqlx::types::Uuid;
use sqlx::{Executor, Postgres};
@@ -14,19 +13,15 @@ pub async fn delete_message_with_tx(
update_thread_metadata: bool,
) -> anyhow::Result<Option<Uuid>> {
// delete the message itself
- delete_db_message(&mut *tx, message.db_id)
- .await
- .context("Failed to delete db message")?;
+ delete_db_message(&mut *tx, message.db_id).await?;
// if it was the only message in the thread, delete the thread too
- let deleted_thread = threads::delete::delete_thread_if_empty(&mut *tx, message.thread_db_id)
- .await
- .context("Failed to attempt thread deletion")?;
+ let deleted_thread =
+ threads::delete::delete_thread_if_empty(&mut *tx, message.thread_db_id).await?;
if !deleted_thread && update_thread_metadata {
threads::update::update_thread_metadata(&mut *tx, message.thread_db_id, message.link_id)
- .await
- .context("Failed to update thread metadata")?;
+ .await?;
}
if deleted_thread {
@@ -44,8 +39,7 @@ where
// Delete the message
let result = sqlx::query!(r#"DELETE FROM email_messages WHERE id = $1"#, message_id)
.execute(executor)
- .await
- .with_context(|| format!("Failed to delete message with id {}", message_id))?;
+ .await?;
// Check if any rows were affected
if result.rows_affected() == 0 {
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 b221e23a3b..ebfb4dbd45 100644
--- a/rust/cloud-storage/email_db_client/src/messages/get.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/get.rs
@@ -41,8 +41,7 @@ pub async fn get_message_sender_and_pretty_sender(
link_id
)
.fetch_all(pool)
- .await
- .context("Failed to fetch message senders")?;
+ .await?;
let mut result = HashMap::new();
for row in rows {
@@ -160,13 +159,7 @@ pub async fn fetch_messages_metadata(
thread_db_id
)
.fetch_all(&mut *conn)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message previews for thread {}",
- thread_db_id
- )
- })?;
+ .await?;
if db_messages.is_empty() {
return Ok(Vec::new());
@@ -174,17 +167,12 @@ pub async fn fetch_messages_metadata(
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 = get::fetch_message_labels_in_bulk(&mut *conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = get::fetch_message_labels_in_bulk(&mut *conn, &message_ids).await?;
let mut processed_messages = Vec::with_capacity(db_messages.len());
for message in db_messages {
@@ -248,13 +236,7 @@ pub async fn fetch_messages_with_labels(
link_id
)
.fetch_all(conn)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message previews for thread {}",
- thread_db_id
- )
- })?;
+ .await?;
if db_messages.is_empty() {
return Ok(Vec::new());
@@ -262,9 +244,7 @@ pub async fn fetch_messages_with_labels(
let message_ids: Vec<Uuid> = db_messages.iter().map(|m| m.id).collect();
- let labels_map = get::fetch_message_labels_in_bulk(conn, &message_ids)
- .await
- .context("Failed to fetch message labels in bulk")?;
+ let labels_map = get::fetch_message_labels_in_bulk(conn, &message_ids).await?;
let mut processed_messages = Vec::with_capacity(db_messages.len());
for message in db_messages {
@@ -283,6 +263,7 @@ pub async fn fetch_messages_with_labels(
}
// gets the headers we need for threading messages correctly
+#[tracing::instrument(skip(pool), err)]
pub async fn get_message_threading_headers(
pool: &PgPool,
message_id: Uuid,
@@ -302,13 +283,7 @@ pub async fn get_message_threading_headers(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch threading headers for message {} with link_id {}",
- message_id, link_id
- )
- })?;
+ .await?;
match row_option {
Some(row) => Ok((row.message_id, row.references)),
@@ -317,7 +292,7 @@ pub async fn get_message_threading_headers(
}
/// Retrieves the ID of a message based on link_id and global_id, if exists
-#[tracing::instrument(skip(executor), level = "debug")]
+#[tracing::instrument(skip(executor), err)]
pub async fn get_message_id_by_global_id<'e, E>(
executor: E,
link_id: Uuid,
@@ -336,13 +311,7 @@ where
global_id
)
.fetch_optional(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message ID for link_id {} and global_id {}",
- link_id, global_id
- )
- })?;
+ .await?;
Ok(message_id)
}
@@ -391,13 +360,7 @@ pub async fn get_message_to_send(
link_id
)
.fetch_one(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch paginated messages for message DB ID {}",
- message_id
- )
- })?;
+ .await?;
// fetch data from each table concurrently
let (sender_res, recipients_res) = tokio::try_join!(
@@ -494,13 +457,7 @@ pub async fn get_messages_by_thread_id(
offset
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch paginated messages for thread DB ID {}",
- thread_db_id
- )
- })?;
+ .await?;
Ok(db_messages)
}
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 02f6d1ecbb..ad8ffd567e 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
@@ -36,13 +36,7 @@ pub async fn get_parsed_message_by_id(
message_id,
)
.fetch_optional(&mut *conn)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message {}",
- message_id
- )
- })?;
+ .await?;
let db_message: db::message::Message = if let Some(db_message) = db_message {
db_message
@@ -165,10 +159,7 @@ pub async fn get_paginated_parsed_messages_by_thread_id(
offset: i64,
limit: i64,
) -> anyhow::Result<Vec<message::ParsedMessage>> {
- let mut conn = pool
- .acquire()
- .await
- .context("failed to acquire connection")?;
+ let mut conn = pool.acquire().await?;
// Get messages for thread
let db_messages: Vec<db::message::Message> = sqlx::query_as!(
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 4995f03983..5e514bbac8 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
@@ -36,13 +36,7 @@ pub async fn get_parsed_search_message_by_id(
message_id,
)
.fetch_optional(&mut *conn)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message {}",
- message_id
- )
- })?;
+ .await?;
let db_message: db::message::Message = if let Some(db_message) = db_message {
db_message
@@ -90,10 +84,7 @@ pub async fn get_paginated_parsed_search_messages_by_thread_id(
offset: i64,
limit: i64,
) -> anyhow::Result<Vec<message::ParsedSearchMessage>> {
- let mut conn = pool
- .acquire()
- .await
- .context("failed to acquire connection")?;
+ let mut conn = pool.acquire().await?;
// Get messages for thread
let db_messages: Vec<db::message::Message> = sqlx::query_as!(
diff --git a/rust/cloud-storage/email_db_client/src/messages/get_simple_messages.rs b/rust/cloud-storage/email_db_client/src/messages/get_simple_messages.rs
index df1300eecd..b204319646 100644
--- a/rust/cloud-storage/email_db_client/src/messages/get_simple_messages.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/get_simple_messages.rs
@@ -1,5 +1,4 @@
use crate::parse::db_to_service::map_db_message_to_simple_message;
-use anyhow::Context;
use models_email::db;
use models_email::service::message;
use sqlx::types::Uuid;
@@ -50,13 +49,7 @@ pub async fn get_simple_message_by_provider_and_link(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message with provider_id {} and link_id {}",
- provider_id, link_id
- )
- })?;
+ .await?;
if let Some(db_message) = db_message {
let simple_message = map_db_message_to_simple_message(db_message);
@@ -93,13 +86,7 @@ pub async fn get_simple_message(
fusionauth_user_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch message {} for user {}",
- message_id, fusionauth_user_id
- )
- })?;
+ .await?;
if let Some(db_message) = db_message {
let simple_message = map_db_message_to_simple_message(db_message);
@@ -139,13 +126,7 @@ pub async fn get_simple_messages_batch(
fusionauth_user_id
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch {} messages for user {}",
- message_ids.len(), fusionauth_user_id
- )
- })?;
+ .await?;
let simple_messages: Vec<message::SimpleMessage> = db_messages
.into_iter()
@@ -206,13 +187,7 @@ where
link_id
)
.fetch_all(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch simple messages for thread {} and link {}",
- thread_id, link_id
- )
- })?;
+ .await?;
let simple_messages: Vec<message::SimpleMessage> = db_messages
.into_iter()
@@ -224,7 +199,7 @@ where
/// Returns the first simple message draft that matches a specific "Macro-In-Reply-To" header value
/// Returns None if no matching message is found
-#[tracing::instrument(skip(pool), level = "debug")]
+#[tracing::instrument(skip(pool), err)]
pub async fn get_first_simple_message_draft(
pool: &PgPool,
link_id: &Uuid,
@@ -256,13 +231,7 @@ pub async fn get_first_simple_message_draft(
replying_to_id.to_string()
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch draft message with Macro-In-Reply-To {} for link_id {}",
- replying_to_id, link_id
- )
- })?;
+ .await?;
Ok(db_message.map(map_db_message_to_simple_message))
}
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 02c3228510..57360feda6 100644
--- a/rust/cloud-storage/email_db_client/src/messages/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/messages/insert.rs
@@ -149,13 +149,7 @@ async fn insert_db_message(
db_message.headers_jsonb
)
.fetch_one(&mut *tx)
- .await
- .with_context(|| {
- format!(
- "Failed to insert/update message with thread_id {} and provider_id {}",
- thread_id, db_message.provider_id.unwrap_or_default()
- )
- })?;
+ .await?;
Ok(result.id)
}
@@ -178,10 +172,7 @@ pub async fn insert_message(
.await
.context("Failed to insert address ids")?;
- let mut tx = pool
- .begin()
- .await
- .context("Failed to begin transaction for message")?;
+ let mut tx = pool.begin().await?;
match insert_message_with_tx(
&mut tx,
@@ -194,9 +185,7 @@ pub async fn insert_message(
.await
{
Ok(_) => {
- tx.commit()
- .await
- .context("Failed to commit transaction for message")?;
+ tx.commit().await?;
Ok(())
}
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 c262a39035..915622306a 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
@@ -32,13 +32,7 @@ where
link_id
)
.fetch_optional(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to update replying_to_id for message {} for link_id {}",
- message_id, link_id
- )
- })?;
+ .await?;
// Return true if a message was updated, false otherwise
let updated = result.is_some();
@@ -89,14 +83,7 @@ where
link_id
)
.execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to bulk update replying_to_id for {} messages for link_id {}",
- updates.len(),
- link_id
- )
- })?;
+ .await?;
let rows_affected = result.rows_affected();
diff --git a/rust/cloud-storage/email_db_client/src/sfs_mappings/mod.rs b/rust/cloud-storage/email_db_client/src/sfs_mappings/mod.rs
index 085844b7ed..43169f5707 100644
--- a/rust/cloud-storage/email_db_client/src/sfs_mappings/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/sfs_mappings/mod.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use sqlx::PgPool;
use std::collections::{HashMap, HashSet};
@@ -14,8 +13,7 @@ pub async fn fetch_sfs_mapping(pool: &PgPool, source: &str) -> anyhow::Result<Op
source
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch SFS mapping for source: {}", source))?;
+ .await?;
Ok(record.map(|r| r.destination))
}
@@ -42,8 +40,7 @@ pub async fn fetch_sfs_mappings(
&sources_vec
)
.fetch_all(pool)
- .await
- .with_context(|| format!("Failed to fetch SFS mappings for sources: {:?}", sources))?;
+ .await?;
let mappings: HashMap<String, String> = records
.into_iter()
@@ -86,13 +83,7 @@ pub async fn insert_sfs_mappings(
&destinations
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to insert SFS mappings for {} source/destination pairs",
- mappings.len()
- )
- })?;
+ .await?;
Ok(result.rows_affected())
}
diff --git a/rust/cloud-storage/email_db_client/src/sync_tokens/get.rs b/rust/cloud-storage/email_db_client/src/sync_tokens/get.rs
index fcc697e200..86c2755d71 100644
--- a/rust/cloud-storage/email_db_client/src/sync_tokens/get.rs
+++ b/rust/cloud-storage/email_db_client/src/sync_tokens/get.rs
@@ -1,9 +1,9 @@
-use anyhow::Context;
use models_email::{db, service};
use sqlx::PgPool;
use sqlx::types::Uuid;
/// fetches the contacts sync tokens for a given link id
+#[tracing::instrument(skip(pool), err)]
pub async fn get_sync_tokens_by_link_id(
pool: &PgPool,
link_id: Uuid,
@@ -18,8 +18,7 @@ pub async fn get_sync_tokens_by_link_id(
link_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch sync token for link_id {}", link_id))?;
+ .await?;
Ok(db_sync_tokens.map(Into::into))
}
diff --git a/rust/cloud-storage/email_db_client/src/sync_tokens/insert.rs b/rust/cloud-storage/email_db_client/src/sync_tokens/insert.rs
index 491f4461bd..983ed988ca 100644
--- a/rust/cloud-storage/email_db_client/src/sync_tokens/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/sync_tokens/insert.rs
@@ -1,8 +1,8 @@
-use anyhow::Context;
use models_email::service;
use sqlx::PgPool;
/// Inserts or updates the sync tokens for a given link id
+#[tracing::instrument(skip(pool), err)]
pub async fn insert_sync_tokens(
pool: &PgPool,
sync_tokens: service::sync_token::SyncTokens,
@@ -21,13 +21,7 @@ pub async fn insert_sync_tokens(
sync_tokens.other_contacts_sync_token
)
.execute(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to insert sync tokens for link_id {}",
- sync_tokens.link_id
- )
- })?;
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_db_client/src/threads/delete.rs b/rust/cloud-storage/email_db_client/src/threads/delete.rs
index 8e613a4d6c..c31787881a 100644
--- a/rust/cloud-storage/email_db_client/src/threads/delete.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/delete.rs
@@ -1,4 +1,3 @@
-use anyhow::Context;
use sqlx::types::Uuid;
/// Deletes a thread if it has no associated messages
@@ -12,8 +11,7 @@ pub async fn delete_thread_if_empty(
thread_id
)
.fetch_one(&mut *tx)
- .await
- .with_context(|| format!("Failed to check if messages exist for thread {}", thread_id))?
+ .await?
.exists;
if messages_exist {
@@ -23,8 +21,7 @@ pub async fn delete_thread_if_empty(
// No messages exist, delete the thread
let result = sqlx::query!(r#"DELETE FROM email_threads WHERE id = $1"#, thread_id)
.execute(&mut *tx)
- .await
- .with_context(|| format!("Failed to delete empty thread {}", thread_id))?;
+ .await?;
if result.rows_affected() == 0 {
tracing::warn!(thread_id = %thread_id, "Thread not found for deletion");
diff --git a/rust/cloud-storage/email_db_client/src/threads/get.rs b/rust/cloud-storage/email_db_client/src/threads/get.rs
index 79e7a5f2ee..c662a64aef 100644
--- a/rust/cloud-storage/email_db_client/src/threads/get.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/get.rs
@@ -1,6 +1,6 @@
use crate::messages::get::{convert_db_messages_to_service_concurrent, get_messages_by_thread_id};
use crate::parse::db_to_service;
-use anyhow::{Context, anyhow};
+use anyhow::anyhow;
use models_email::email::db;
use models_email::email::service::thread;
use models_email::email::service::thread::{
@@ -30,8 +30,7 @@ pub async fn get_paginated_thread_ids_with_macro_user_id(
)
.map(|row| (row.id, row.macro_id))
.fetch_all(pool)
- .await
- .context("Failed to fetch thread ids with macro user id")?;
+ .await?;
Ok(result)
}
@@ -60,8 +59,7 @@ pub async fn fetch_thread_with_messages_paginated(
thread_db_id,
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch thread with DB ID {}", thread_db_id))?;
+ .await?;
let Some(db_thread) = db_thread else {
return Ok(None);
@@ -103,14 +101,8 @@ pub async fn get_latest_thread_ids_paginated(
limit,
offset
)
- .fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch latest thread IDs for links associated with user {} with limit {} offset {}",
- fusionauth_user_id, limit, offset
- )
- })?;
+ .fetch_all(pool)
+ .await?;
Ok(thread_ids)
}
@@ -139,13 +131,7 @@ pub async fn get_threads_by_link_id_and_provider_ids(
&provider_ids_vec
)
.fetch_all(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch threads by link_id {} and provider_ids {:?}",
- link_id, provider_ids_vec
- )
- })?;
+ .await?;
// Build the result map
let thread_map = rows
@@ -157,6 +143,7 @@ pub async fn get_threads_by_link_id_and_provider_ids(
}
/// For a user, get threads where user has sent a message, paginated.
+#[tracing::instrument(skip(pool), err)]
pub async fn get_threads_by_user_with_outbound(
pool: &PgPool,
macro_user_id: &str,
@@ -194,6 +181,7 @@ pub async fn get_threads_by_user_with_outbound(
}
/// For a list of user to thread IDs, filter out threads where user has not sent a message
+#[tracing::instrument(skip(pool), err)]
pub async fn get_outbound_threads_by_thread_ids(
pool: &PgPool,
user_thread_ids: Vec<UserThreadIds>,
@@ -275,13 +263,7 @@ pub async fn get_provider_id_by_link_and_thread_id(
thread_db_id
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch provider_id for thread ID {} with link_id {}",
- thread_db_id, link_id
- )
- })?
+ .await?
.flatten();
Ok(provider_id)
@@ -302,8 +284,7 @@ pub async fn get_macro_id_from_thread_id(
thread_id
)
.fetch_optional(pool)
- .await
- .with_context(|| format!("Failed to fetch macro_id for thread ID {}", thread_id))?;
+ .await?;
Ok(macro_id)
}
@@ -329,13 +310,7 @@ pub async fn get_thread_by_id_and_link_id(
link_id,
)
.fetch_optional(pool)
- .await
- .with_context(|| {
- format!(
- "Failed to fetch thread with ID {} and link_id {}",
- thread_id, link_id
- )
- })?;
+ .await?;
// If no thread found, return None
if let Some(db_thread) = db_thread {
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 4bc970cccc..6df7219792 100644
--- a/rust/cloud-storage/email_db_client/src/threads/insert.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/insert.rs
@@ -39,7 +39,7 @@ pub async fn insert_thread_and_messages(
recipient_map.insert(message.provider_id.clone().unwrap(), recipients);
}
- let mut tx = pool.begin().await.context("Failed to begin transaction")?;
+ let mut tx = pool.begin().await?;
let result = async {
// Insert thread
@@ -87,7 +87,7 @@ pub async fn insert_thread_and_messages(
return Err(err);
}
- tx.commit().await.context("Failed to commit transaction")?;
+ tx.commit().await?;
Ok(result.unwrap())
}
@@ -125,11 +125,7 @@ where
db_thread.latest_non_spam_message_ts,
)
.fetch_one(executor)
- .await
- .context(format!(
- "Failed to upsert thread with provider id {} for link_id {}",
- db_thread.provider_id.unwrap_or_default(), db_thread.link_id
- ))?;
+ .await?;
Ok(result.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 af049ae030..a3175633f8 100644
--- a/rust/cloud-storage/email_db_client/src/threads/update.rs
+++ b/rust/cloud-storage/email_db_client/src/threads/update.rs
@@ -42,11 +42,7 @@ async fn update_db_thread_metadata(
link_id,
)
.execute(tx)
- .await
- .context(format!(
- "Failed to update timestamps for thread ID {} with link_id {}",
- thread_id, link_id
- ))?;
+ .await?;
Ok(())
}
@@ -74,11 +70,7 @@ pub async fn update_inbox_visible_status(
link_id,
)
.execute(conn)
- .await
- .context(format!(
- "Failed to update archived status to {} for thread ID {} with link_id {}",
- inbox_visible, thread_id, link_id
- ))?;
+ .await?;
Ok(())
}
@@ -136,11 +128,7 @@ pub async fn update_thread_provider_id(
link_id,
)
.execute(conn)
- .await
- .context(format!(
- "Failed to update provider_id to '{}' for thread ID {} with link_id {}",
- provider_id, thread_id, link_id
- ))?;
+ .await?;
Ok(())
}