diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index b2ddbced0..fdc1a198d 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -925,6 +925,8 @@ pub unsafe extern "C" fn dc_get_fresh_msgs( let arr = dc_array_t::from( ctx.get_fresh_msgs() .await + .log_err(ctx, "Failed to get fresh messages") + .unwrap_or_default() .iter() .map(|msg_id| msg_id.to_u32()) .collect::>(), diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index b3fcb2b93..2005defe6 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -1000,7 +1000,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu println!("HTML written to: {:#?}", file); } "listfresh" => { - let msglist = context.get_fresh_msgs().await; + let msglist = context.get_fresh_msgs().await?; log_msglist(&context, &msglist).await?; print!("{} fresh messages.", msglist.len()); diff --git a/src/context.rs b/src/context.rs index f6dec7c9c..d428048d2 100644 --- a/src/context.rs +++ b/src/context.rs @@ -431,8 +431,9 @@ impl Context { /// and is typically used to show notifications. /// Moreover, the number of returned messages /// can be used for a badge counter on the app icon. - pub async fn get_fresh_msgs(&self) -> Vec { - self.sql + pub async fn get_fresh_msgs(&self) -> Result> { + let ret = self + .sql .query_map( concat!( "SELECT m.id", @@ -459,8 +460,8 @@ impl Context { Ok(ret) }, ) - .await - .unwrap_or_default() + .await?; + Ok(ret) } /// Searches for messages containing the query string. @@ -610,7 +611,7 @@ mod tests { #[async_std::test] async fn test_get_fresh_msgs() { let t = TestContext::new().await; - let fresh = t.get_fresh_msgs().await; + let fresh = t.get_fresh_msgs().await.unwrap(); assert!(fresh.is_empty()) }