From 9e78aaa75196e53cef2a7e41a4c4f2f5f396c5a4 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Thu, 17 Oct 2024 17:30:45 +0200 Subject: [PATCH] Add context to iteration errors --- crates/common/src/core.rs | 1 + crates/common/src/manager/config.rs | 4 +++- crates/directory/src/backend/internal/lookup.rs | 2 +- crates/jmap/src/api/management/queue.rs | 6 ++++-- crates/jmap/src/api/management/report.rs | 2 +- crates/jmap/src/services/index.rs | 2 +- crates/smtp/src/reporting/dmarc.rs | 4 ++-- crates/smtp/src/reporting/tls.rs | 4 ++-- crates/store/src/fts/index.rs | 4 +++- crates/store/src/fts/query.rs | 4 +++- crates/store/src/write/mod.rs | 2 ++ 11 files changed, 23 insertions(+), 12 deletions(-) diff --git a/crates/common/src/core.rs b/crates/common/src/core.rs index e81d3e80..31ed0bf7 100644 --- a/crates/common/src/core.rs +++ b/crates/common/src/core.rs @@ -168,6 +168,7 @@ impl Server { }, ) .await + .caused_by(trc::location!()) .map(|_| total) } diff --git a/crates/common/src/manager/config.rs b/crates/common/src/manager/config.rs index 07b2668d..3a8c0b0e 100644 --- a/crates/common/src/manager/config.rs +++ b/crates/common/src/manager/config.rs @@ -16,6 +16,7 @@ use store::{ write::{BatchBuilder, ValueClass}, Deserialize, IterateParams, Store, ValueKey, }; +use trc::AddContext; use utils::{ config::{Config, ConfigKey}, glob::GlobPattern, @@ -166,7 +167,8 @@ impl ConfigManager { Ok(true) }, ) - .await?; + .await + .caused_by(trc::location!())?; Ok(results) } diff --git a/crates/directory/src/backend/internal/lookup.rs b/crates/directory/src/backend/internal/lookup.rs index 54987f90..173a8edd 100644 --- a/crates/directory/src/backend/internal/lookup.rs +++ b/crates/directory/src/backend/internal/lookup.rs @@ -135,7 +135,7 @@ impl DirectoryStore for Store { Ok(true) }, ) - .await?; + .await.caused_by(trc::location!())?; } Ok(results) diff --git a/crates/jmap/src/api/management/queue.rs b/crates/jmap/src/api/management/queue.rs index c19bc707..beddd94d 100644 --- a/crates/jmap/src/api/management/queue.rs +++ b/crates/jmap/src/api/management/queue.rs @@ -257,7 +257,8 @@ impl QueueManagement for Server { Ok(max_total == 0 || total < max_total) }, ) - .await?; + .await + .caused_by(trc::location!())?; Ok(if values { JsonResponse::new(json!({ @@ -512,7 +513,8 @@ impl QueueManagement for Server { Ok(max_total == 0 || total < max_total) }, ) - .await?; + .await + .caused_by(trc::location!())?; Ok(JsonResponse::new(json!({ "data": { diff --git a/crates/jmap/src/api/management/report.rs b/crates/jmap/src/api/management/report.rs index 5540d41b..12c3d89c 100644 --- a/crates/jmap/src/api/management/report.rs +++ b/crates/jmap/src/api/management/report.rs @@ -227,7 +227,7 @@ impl ManageReports for Server { Ok(max_total == 0 || total < max_total) }, ) - .await?; + .await.caused_by(trc::location!())?; Ok(JsonResponse::new(json!({ "data": { diff --git a/crates/jmap/src/services/index.rs b/crates/jmap/src/services/index.rs index 7481cbee..7b784e6d 100644 --- a/crates/jmap/src/services/index.rs +++ b/crates/jmap/src/services/index.rs @@ -118,7 +118,7 @@ impl Indexer for Server { ) .await .map_err(|err| { - trc::error!(err.details("Failed to iterate over index emails")); + trc::error!(err.caused_by(trc::location!()).details("Failed to iterate over index emails")); }); // Add entries to the index diff --git a/crates/smtp/src/reporting/dmarc.rs b/crates/smtp/src/reporting/dmarc.rs index 5b106fea..646dec15 100644 --- a/crates/smtp/src/reporting/dmarc.rs +++ b/crates/smtp/src/reporting/dmarc.rs @@ -24,7 +24,7 @@ use store::{ write::{now, BatchBuilder, Bincode, QueueClass, ReportEvent, ValueClass}, Deserialize, IterateParams, Serialize, ValueKey, }; -use trc::OutgoingReportEvent; +use trc::{AddContext, OutgoingReportEvent}; use utils::config::Rate; use crate::{ @@ -559,7 +559,7 @@ impl DmarcReporting for Server { } }, ) - .await?; + .await.caused_by(trc::location!())?; for (record, count) in record_map { report = report.with_record(record.with_count(count)); diff --git a/crates/smtp/src/reporting/tls.rs b/crates/smtp/src/reporting/tls.rs index 0430badb..9a0c8762 100644 --- a/crates/smtp/src/reporting/tls.rs +++ b/crates/smtp/src/reporting/tls.rs @@ -30,7 +30,7 @@ use store::{ write::{now, BatchBuilder, Bincode, QueueClass, ReportEvent, ValueClass}, Deserialize, IterateParams, Serialize, ValueKey, }; -use trc::OutgoingReportEvent; +use trc::{AddContext, OutgoingReportEvent}; use crate::{queue::RecipientDomain, reporting::SmtpReporting}; @@ -366,7 +366,7 @@ impl TlsReporting for Server { Ok(true) } }) - .await?; + .await.caused_by(trc::location!())?; // Add policy report.policies.push(Policy { diff --git a/crates/store/src/fts/index.rs b/crates/store/src/fts/index.rs index 6795a80a..fd2d3ba2 100644 --- a/crates/store/src/fts/index.rs +++ b/crates/store/src/fts/index.rs @@ -15,6 +15,7 @@ use nlp::{ }, tokenizers::word::WordTokenizer, }; +use trc::AddContext; use crate::{ backend::MAX_TOKEN_LENGTH, @@ -294,7 +295,8 @@ impl Store { Ok(true) }, ) - .await?; + .await + .caused_by(trc::location!())?; // Remove keys let mut batch = BatchBuilder::new(); diff --git a/crates/store/src/fts/query.rs b/crates/store/src/fts/query.rs index c95f4ea3..7b802a10 100644 --- a/crates/store/src/fts/query.rs +++ b/crates/store/src/fts/query.rs @@ -12,6 +12,7 @@ use std::{ use ahash::AHashMap; use nlp::language::stemmer::Stemmer; use roaring::RoaringBitmap; +use trc::AddContext; use crate::{ backend::MAX_TOKEN_LENGTH, @@ -381,7 +382,8 @@ impl Store { Ok(true) }, ) - .await?; + .await + .caused_by(trc::location!())?; if is_intersect { if is_first { diff --git a/crates/store/src/write/mod.rs b/crates/store/src/write/mod.rs index 9d513cad..3ea2064b 100644 --- a/crates/store/src/write/mod.rs +++ b/crates/store/src/write/mod.rs @@ -703,12 +703,14 @@ impl De lz4_flex::decompress_size_prepended(bytes) .map_err(|err| { trc::StoreEvent::DecompressError + .ctx(trc::Key::Value, bytes) .caused_by(trc::location!()) .reason(err) }) .and_then(|result| { bincode::deserialize(&result).map_err(|err| { trc::StoreEvent::DataCorruption + .ctx(trc::Key::Value, bytes) .caused_by(trc::location!()) .reason(err) })