Skip to content

Commit 5a79703

Browse files
sandhosereivilibre
authored andcommitted
Better report errors when a writing task fails
1 parent 03fd1b2 commit 5a79703

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

crates/syn2mas/src/migration.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{pin::pin, time::Instant};
1515

1616
use chrono::{DateTime, Utc};
1717
use compact_str::CompactString;
18-
use futures_util::{SinkExt, StreamExt as _, TryStreamExt as _};
18+
use futures_util::{SinkExt, StreamExt as _, TryFutureExt, TryStreamExt as _};
1919
use mas_storage::Clock;
2020
use rand::{RngCore, SeedableRng};
2121
use thiserror::Error;
@@ -277,14 +277,19 @@ async fn migrate_users(
277277
.instrument(tracing::info_span!("ingest_task")),
278278
);
279279

280-
synapse
280+
// In case this has an error, we still want to join the task, so we look at the
281+
// error later
282+
let res = synapse
281283
.read_users()
282284
.map_err(|e| e.into_synapse("reading users"))
283285
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
284-
.await?;
286+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
287+
.await;
285288

286289
let (mas, state) = task.await.into_join("user write task")??;
287290

291+
res?;
292+
288293
info!(
289294
"users migrated in {:.1}s",
290295
Instant::now().duration_since(start).as_secs_f64()
@@ -570,14 +575,19 @@ async fn migrate_devices(
570575
.instrument(tracing::info_span!("ingest_task")),
571576
);
572577

573-
synapse
578+
// In case this has an error, we still want to join the task, so we look at the
579+
// error later
580+
let res = synapse
574581
.read_devices()
575582
.map_err(|e| e.into_synapse("reading devices"))
576583
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
577-
.await?;
584+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
585+
.await;
578586

579587
let (mas, state) = task.await.into_join("device write task")??;
580588

589+
res?;
590+
581591
info!(
582592
"devices migrated in {:.1}s",
583593
Instant::now().duration_since(start).as_secs_f64()
@@ -709,14 +719,19 @@ async fn migrate_unrefreshable_access_tokens(
709719
.instrument(tracing::info_span!("ingest_task")),
710720
);
711721

712-
synapse
722+
// In case this has an error, we still want to join the task, so we look at the
723+
// error later
724+
let res = synapse
713725
.read_unrefreshable_access_tokens()
714726
.map_err(|e| e.into_synapse("reading tokens"))
715727
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
716-
.await?;
728+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
729+
.await;
717730

718731
let (mas, state) = task.await.into_join("token write task")??;
719732

733+
res?;
734+
720735
info!(
721736
"non-refreshable access tokens migrated in {:.1}s",
722737
Instant::now().duration_since(start).as_secs_f64()

0 commit comments

Comments
 (0)