Skip to content

Commit ea8876a

Browse files
committed
Better report errors when a writing task fails
1 parent 5ef27cc commit ea8876a

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;
@@ -310,15 +310,20 @@ async fn migrate_users(
310310
.instrument(tracing::info_span!("ingest_task")),
311311
);
312312

313-
synapse
313+
// In case this has an error, we still want to join the task, so we look at the
314+
// error later
315+
let res = synapse
314316
.read_users()
315317
.with_progress_bar(count_hint, 10_000)
316318
.map_err(|e| e.into_synapse("reading users"))
317319
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
318-
.await?;
320+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
321+
.await;
319322

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

325+
res?;
326+
322327
info!(
323328
"users migrated in {:.1}s",
324329
Instant::now().duration_since(start).as_secs_f64()
@@ -624,15 +629,20 @@ async fn migrate_devices(
624629
.instrument(tracing::info_span!("ingest_task")),
625630
);
626631

627-
synapse
632+
// In case this has an error, we still want to join the task, so we look at the
633+
// error later
634+
let res = synapse
628635
.read_devices()
629636
.with_progress_bar(count_hint, 10_000)
630637
.map_err(|e| e.into_synapse("reading devices"))
631638
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
632-
.await?;
639+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
640+
.await;
633641

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

644+
res?;
645+
636646
info!(
637647
"devices migrated in {:.1}s",
638648
Instant::now().duration_since(start).as_secs_f64()
@@ -761,15 +771,20 @@ async fn migrate_unrefreshable_access_tokens(
761771
.instrument(tracing::info_span!("ingest_task")),
762772
);
763773

764-
synapse
774+
// In case this has an error, we still want to join the task, so we look at the
775+
// error later
776+
let res = synapse
765777
.read_unrefreshable_access_tokens()
766778
.with_progress_bar(count_hint, 10_000)
767779
.map_err(|e| e.into_synapse("reading tokens"))
768780
.forward(PollSender::new(tx).sink_map_err(|_| Error::ChannelClosed))
769-
.await?;
781+
.inspect_err(|e| tracing::error!(error = e as &dyn std::error::Error))
782+
.await;
770783

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

786+
res?;
787+
773788
info!(
774789
"non-refreshable access tokens migrated in {:.1}s",
775790
Instant::now().duration_since(start).as_secs_f64()

0 commit comments

Comments
 (0)