Skip to content

Commit

Permalink
Add context to iteration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Oct 17, 2024
1 parent a1c5be0 commit 9e78aaa
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/common/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl Server {
},
)
.await
.caused_by(trc::location!())
.map(|_| total)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/common/src/manager/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use store::{
write::{BatchBuilder, ValueClass},
Deserialize, IterateParams, Store, ValueKey,
};
use trc::AddContext;
use utils::{
config::{Config, ConfigKey},
glob::GlobPattern,
Expand Down Expand Up @@ -166,7 +167,8 @@ impl ConfigManager {
Ok(true)
},
)
.await?;
.await
.caused_by(trc::location!())?;

Ok(results)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/directory/src/backend/internal/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl DirectoryStore for Store {
Ok(true)
},
)
.await?;
.await.caused_by(trc::location!())?;
}

Ok(results)
Expand Down
6 changes: 4 additions & 2 deletions crates/jmap/src/api/management/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/src/api/management/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/src/services/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/smtp/src/reporting/dmarc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions crates/smtp/src/reporting/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -366,7 +366,7 @@ impl TlsReporting for Server {
Ok(true)
}
})
.await?;
.await.caused_by(trc::location!())?;

// Add policy
report.policies.push(Policy {
Expand Down
4 changes: 3 additions & 1 deletion crates/store/src/fts/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use nlp::{
},
tokenizers::word::WordTokenizer,
};
use trc::AddContext;

use crate::{
backend::MAX_TOKEN_LENGTH,
Expand Down Expand Up @@ -294,7 +295,8 @@ impl Store {
Ok(true)
},
)
.await?;
.await
.caused_by(trc::location!())?;

// Remove keys
let mut batch = BatchBuilder::new();
Expand Down
4 changes: 3 additions & 1 deletion crates/store/src/fts/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -381,7 +382,8 @@ impl Store {
Ok(true)
},
)
.await?;
.await
.caused_by(trc::location!())?;

if is_intersect {
if is_first {
Expand Down
2 changes: 2 additions & 0 deletions crates/store/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,14 @@ impl<T: serde::Serialize + serde::de::DeserializeOwned + Sized + Sync + Send> 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)
})
Expand Down

0 comments on commit 9e78aaa

Please sign in to comment.