Skip to content

Commit

Permalink
main: ignore errors
Browse files Browse the repository at this point in the history
This prevents `moo` from panicking when the matrix server
has some communication issues. It will now retry in a 5
second loop.
  • Loading branch information
hinto-janai committed Jul 30, 2024
1 parent c0dc4ed commit 129eb21
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ pub mod sweeper;
pub mod sync;

//---------------------------------------------------------------------------------------------------- Use
use std::{sync::Arc, time::SystemTime};
use std::{
sync::Arc,
time::{Duration, SystemTime},
};

use constants::{CLIENT, CONFIG, INIT_INSTANT};
use matrix_sdk::ruma::events::room::message::SyncRoomMessageEvent;
use tracing::info;
use tracing::{error, info};

//---------------------------------------------------------------------------------------------------- Main
#[tokio::main]
Expand Down Expand Up @@ -179,9 +182,24 @@ async fn main() {
});
}

// Hang forever (until error).
match CLIENT.sync(sync::sync_settings()).await {
Ok(()) => shutdown::graceful_shutdown(db),
Err(e) => panic!("{e}"),
// Sync forever, ignore errors.
loop {
match CLIENT.sync(sync::sync_settings()).await {
Ok(()) => {
shutdown::graceful_shutdown(db);
std::process::exit(0);
}

// This sometimes runs into:
// `the server returned an error: [404] <non-json bytes>`
// which can be ignored.
Err(e) => {
/// How long to sleep for before trying to sync again.
const SLEEP: Duration = Duration::from_secs(5);
error!("sync error: {e:?}");
info!("re-syncing after: {SLEEP:?}");
tokio::time::sleep(SLEEP).await;
}
}
}
}

0 comments on commit 129eb21

Please sign in to comment.