From 57871bbaf891710a9c74f97f8a0f17d9b66204f0 Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 14 Oct 2024 05:28:39 +0000 Subject: [PATCH] refactor(set_protection_for_timestamp_sort): do not log bubbled up errors Otherwise error may be logged twice. --- src/chat.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index b2ef3533b..61bbacafd 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -589,20 +589,16 @@ impl ChatId { timestamp_sort: i64, contact_id: Option, ) -> Result<()> { - match self.inner_set_protection(context, protect).await { - Ok(protection_status_modified) => { - if protection_status_modified { - self.add_protection_msg(context, protect, contact_id, timestamp_sort) - .await?; - chatlist_events::emit_chatlist_item_changed(context, self); - } - Ok(()) - } - Err(e) => { - error!(context, "Cannot set protection: {e:#}."); // make error user-visible - Err(e) - } + let protection_status_modified = self + .inner_set_protection(context, protect) + .await + .with_context(|| format!("Cannot set protection for {self}"))?; + if protection_status_modified { + self.add_protection_msg(context, protect, contact_id, timestamp_sort) + .await?; + chatlist_events::emit_chatlist_item_changed(context, self); } + Ok(()) } /// Sets protection and sends or adds a message.