diff --git a/deltachat-repl/src/cmdline.rs b/deltachat-repl/src/cmdline.rs index 9fdc8e91e..dc4f75e12 100644 --- a/deltachat-repl/src/cmdline.rs +++ b/deltachat-repl/src/cmdline.rs @@ -563,7 +563,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu context.maybe_network().await; } "housekeeping" => { - sql::housekeeping(&context).await.ok_or_log(&context); + sql::housekeeping(&context).await.log_err(&context).ok(); } "listchats" | "listarchived" | "chats" => { let listflags = if arg0 == "listarchived" { diff --git a/src/blob.rs b/src/blob.rs index 93bfbb3c5..c7a3641d2 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -92,7 +92,7 @@ impl<'a> BlobObject<'a> { if attempt >= MAX_ATTEMPT { return Err(err).context("failed to create file"); } else if attempt == 1 && !dir.exists() { - fs::create_dir_all(dir).await.ok_or_log(context); + fs::create_dir_all(dir).await.log_err(context).ok(); } else { name = format!("{}-{}{}", stem, rand::random::(), ext); } diff --git a/src/ephemeral.rs b/src/ephemeral.rs index 75fb1c127..55bc6b76d 100644 --- a/src/ephemeral.rs +++ b/src/ephemeral.rs @@ -575,7 +575,8 @@ pub(crate) async fn ephemeral_loop(context: &Context, interrupt_receiver: Receiv delete_expired_messages(context, time()) .await - .ok_or_log(context); + .log_err(context) + .ok(); } } diff --git a/src/imex.rs b/src/imex.rs index 885187cae..c9cf6cc68 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -759,7 +759,7 @@ async fn export_database(context: &Context, dest: &Path, passphrase: String) -> .with_context(|| format!("path {} is not valid unicode", dest.display()))?; context.sql.set_raw_config_int("backup_time", now).await?; - sql::housekeeping(context).await.ok_or_log(context); + sql::housekeeping(context).await.log_err(context).ok(); context .sql .call_write(|conn| { diff --git a/src/log.rs b/src/log.rs index 10daed67c..78e41039f 100644 --- a/src/log.rs +++ b/src/log.rs @@ -65,9 +65,6 @@ pub trait LogExt where Self: std::marker::Sized, { - #[track_caller] - fn log_err_inner(self, context: &Context) -> Result; - /// Emits a warning if the receiver contains an Err value. /// /// Thanks to the [track_caller](https://blog.rust-lang.org/2020/08/27/Rust-1.46.0.html#track_caller) @@ -76,36 +73,15 @@ where /// Unfortunately, the track_caller feature does not work on async functions (as of Rust 1.50). /// Once it is, you can add `#[track_caller]` to helper functions that use one of the log helpers here /// so that the location of the caller can be seen in the log. (this won't work with the macros, - /// like warn!(), since the file!() and line!() macros don't work with track_caller) + /// like warn!(), since the file!() and line!() macros don't work with track_caller) /// See for progress on this. #[track_caller] - fn log_err(self, context: &Context) -> Result { - self.log_err_inner(context) - } - - /// Emits a warning if the receiver contains an Err value and returns an [`Option`]. - /// - /// Example: - /// ```text - /// if let Err(e) = do_something() { - /// warn!(context, "{:#}", e); - /// } - /// ``` - /// is equivalent to: - /// ```text - /// do_something().ok_or_log(context); - /// ``` - /// - /// For a note on the `track_caller` feature, see the doc comment on `log_err()`. - #[track_caller] - fn ok_or_log(self, context: &Context) -> Option { - self.log_err_inner(context).ok() - } + fn log_err(self, context: &Context) -> Result; } impl LogExt for Result { #[track_caller] - fn log_err_inner(self, context: &Context) -> Result { + fn log_err(self, context: &Context) -> Result { if let Err(e) = &self { let location = std::panic::Location::caller(); diff --git a/src/scheduler.rs b/src/scheduler.rs index 25e87e220..1c1d3eb5d 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -303,7 +303,7 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne let next_housekeeping_time = last_housekeeping_time.saturating_add(60 * 60 * 24); if next_housekeeping_time <= time() { - sql::housekeeping(&ctx).await.ok_or_log(&ctx); + sql::housekeeping(&ctx).await.log_err(&ctx).ok(); } } Err(err) => { @@ -412,7 +412,8 @@ async fn fetch_idle( .store_seen_flags_on_imap(ctx) .await .context("store_seen_flags_on_imap") - .ok_or_log(ctx); + .log_err(ctx) + .ok(); } else { warn!(ctx, "No session even though we just prepared it"); } @@ -436,7 +437,8 @@ async fn fetch_idle( delete_expired_imap_messages(ctx) .await .context("delete_expired_imap_messages") - .ok_or_log(ctx); + .log_err(ctx) + .ok(); // Scan additional folders only after finishing fetching the watched folder. // @@ -476,7 +478,8 @@ async fn fetch_idle( .sync_seen_flags(ctx, &watch_folder) .await .context("sync_seen_flags") - .ok_or_log(ctx); + .log_err(ctx) + .ok(); connection.connectivity.set_connected(ctx).await; @@ -772,20 +775,22 @@ impl Scheduler { pub(crate) async fn stop(self, context: &Context) { // Send stop signals to tasks so they can shutdown cleanly. for b in self.boxes() { - b.conn_state.stop().await.ok_or_log(context); + b.conn_state.stop().await.log_err(context).ok(); } - self.smtp.stop().await.ok_or_log(context); + self.smtp.stop().await.log_err(context).ok(); // Actually shutdown tasks. let timeout_duration = std::time::Duration::from_secs(30); for b in once(self.inbox).chain(self.oboxes.into_iter()) { tokio::time::timeout(timeout_duration, b.handle) .await - .ok_or_log(context); + .log_err(context) + .ok(); } tokio::time::timeout(timeout_duration, self.smtp_handle) .await - .ok_or_log(context); + .log_err(context) + .ok(); self.ephemeral_handle.abort(); self.location_handle.abort(); self.recently_seen_loop.abort(); diff --git a/src/scheduler/connectivity.rs b/src/scheduler/connectivity.rs index 91edcad61..9febb8b67 100644 --- a/src/scheduler/connectivity.rs +++ b/src/scheduler/connectivity.rs @@ -337,7 +337,7 @@ impl Context { let mut folder_added = false; if let Some(config) = folder.to_config().filter(|c| watched_folders.contains(c)) { - let f = self.get_config(config).await.ok_or_log(self).flatten(); + let f = self.get_config(config).await.log_err(self).ok().flatten(); if let Some(foldername) = f { let detailed = &state.get_detailed().await;