feat(ui): sync_service::State::Error contains the cause error.

This patch updates the `State::Error` variant to contain the error that
led to this state.
This commit is contained in:
Ivan Enderlin
2025-09-05 13:58:41 +02:00
parent 6dbdffd36e
commit b1c28f4bc1
4 changed files with 15 additions and 17 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ impl From<MatrixSyncServiceState> for SyncServiceState {
MatrixSyncServiceState::Idle => Self::Idle,
MatrixSyncServiceState::Running => Self::Running,
MatrixSyncServiceState::Terminated => Self::Terminated,
MatrixSyncServiceState::Error => Self::Error,
MatrixSyncServiceState::Error(_error) => Self::Error,
MatrixSyncServiceState::Offline => Self::Offline,
}
}
+11 -13
View File
@@ -70,7 +70,10 @@ pub enum State {
Terminated,
/// Any of the underlying syncs has ran into an error.
Error,
///
/// The associated [`enum@Error`] is inside an [`Arc`] to (i) make [`State`]
/// cloneable, and to (ii) not make it heavier.
Error(Arc<Error>),
/// The service has entered offline mode. This state will only be entered if
/// the [`SyncService`] has been built with the
@@ -305,15 +308,15 @@ impl SyncTaskSupervisor {
error!("when awaiting encryption sync: {err:#}");
}
if report.is_error() {
if let Some(error) = report.error {
if offline_mode {
state.set(State::Offline);
let client = room_list_service.client();
if let Some(report) = Self::offline_check(client, &mut receiver).await {
if report.is_error() {
state.set(State::Error);
if let Some(error) = report.error {
state.set(State::Error(Arc::new(error)));
} else {
state.set(State::Idle);
}
@@ -322,7 +325,7 @@ impl SyncTaskSupervisor {
state.set(State::Running);
} else {
state.set(State::Error);
state.set(State::Error(Arc::new(error)));
break;
}
} else if matches!(report.origin, TerminationOrigin::Supervisor) {
@@ -567,7 +570,7 @@ impl SyncServiceInner {
/// eprintln!("The sync service has been gracefully terminated");
/// break;
/// }
/// State::Error => {
/// State::Error(_) => {
/// eprintln!("The sync service has run into an error");
/// break;
/// }
@@ -635,7 +638,7 @@ impl SyncService {
.await
}
// Otherwise just start.
State::Idle | State::Terminated | State::Error => {
State::Idle | State::Terminated | State::Error(_) => {
inner
.start(self.room_list_service.clone(), self.encryption_sync_permit.clone())
.await
@@ -653,7 +656,7 @@ impl SyncService {
let mut inner = self.inner.lock().await;
match inner.state.get() {
State::Idle | State::Terminated | State::Error => {
State::Idle | State::Terminated | State::Error(_) => {
// No need to stop if we were not running.
return;
}
@@ -734,11 +737,6 @@ impl TerminationReport {
Self { origin: TerminationOrigin::Supervisor, error: None }
}
/// Check whether the report is about an error.
fn is_error(&self) -> bool {
self.error.is_some()
}
/// Check whether the termination is due to an expired sliding sync session.
fn has_expired(&self) -> bool {
match &self.error {
+1 -1
View File
@@ -463,7 +463,7 @@ impl OAuthCli {
}
}
matrix_sdk_ui::sync_service::State::Error | matrix_sdk_ui::sync_service::State::Offline => {
matrix_sdk_ui::sync_service::State::Error(_) | matrix_sdk_ui::sync_service::State::Offline => {
num_errors += 1;
num_running = 0;
@@ -59,7 +59,7 @@ impl DeveloperSettingsView {
sync_service::State::Running => sync_service.stop().await,
sync_service::State::Idle
| sync_service::State::Terminated
| sync_service::State::Error
| sync_service::State::Error(_)
| sync_service::State::Offline => sync_service.start().await,
}
}
@@ -86,7 +86,7 @@ impl Widget for &mut DeveloperSettingsView {
sync_service::State::Running => ListItem::new("Sync [x]"),
sync_service::State::Idle
| sync_service::State::Terminated
| sync_service::State::Error
| sync_service::State::Error(_)
| sync_service::State::Offline => ListItem::new("Sync [ ]"),
};