Skip to content

Commit 988180f

Browse files
chore: More information on panic in background mode (#343)
1 parent 1f5ea19 commit 988180f

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

applogic/src/background_execution/processing.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use crate::api::user::User;
1111
use super::{NotificationBatch, NotificationContent};
1212

1313
/// TODO: Debug code to be removed
14-
pub(crate) fn error_batch(e: String) -> NotificationBatch {
14+
pub(crate) fn error_batch(title: String, body: String) -> NotificationBatch {
1515
NotificationBatch {
1616
badge_count: 0,
1717
removals: Vec::new(),
1818
additions: vec![NotificationContent {
1919
identifier: "".to_string(),
20-
title: "Error".to_string(),
21-
body: e,
20+
title,
21+
body,
2222
data: "".to_string(),
2323
}],
2424
}
@@ -32,21 +32,29 @@ pub(crate) fn retrieve_messages_sync(path: String) -> NotificationBatch {
3232
.build()
3333
.map_err(|error| {
3434
error!(%error, "Failed to initialize tokio runtime");
35-
error.to_string()
35+
("Runtime error".to_string(), error.to_string())
3636
})
3737
.and_then(|runtime| {
3838
panic::catch_unwind(AssertUnwindSafe(|| {
3939
runtime.block_on(async { retrieve_messages(path).await })
4040
}))
41-
.map_err(|_| {
42-
error!("Failed to execute async function");
43-
"Failed to execute async function".to_string()
41+
.map_err(|payload| {
42+
if let Some(s) = payload.downcast_ref::<&str>() {
43+
error!("Panic in tokio runtime: {}", s);
44+
("Panic in tokio runtime".to_string(), s.to_string())
45+
} else if let Some(s) = payload.downcast_ref::<String>() {
46+
error!("Panic in tokio runtime: {}", s);
47+
("Panic in tokio runtime".to_string(), s.clone())
48+
} else {
49+
error!("Panic in tokio runtime occurred with unknown payload type");
50+
("Panic in tokio runtime".to_string(), "Unknown".to_string())
51+
}
4452
})
4553
});
4654

4755
match result {
4856
Ok(batch) => batch,
49-
Err(e) => error_batch(e),
57+
Err((title, body)) => error_batch(title, body),
5058
}
5159
}
5260

@@ -57,11 +65,14 @@ pub(crate) async fn retrieve_messages(path: String) -> NotificationBatch {
5765
Ok(Some(user)) => user,
5866
Ok(None) => {
5967
error!("User not found");
60-
return error_batch("User not found".to_string());
68+
return error_batch(
69+
"User not found".to_string(),
70+
"The database contained no user data".to_string(),
71+
);
6172
}
6273
Err(error) => {
6374
error!(%error, "Failed to load user");
64-
return error_batch(error.to_string());
75+
return error_batch("Failed to load user".to_string(), error.to_string());
6576
}
6677
};
6778

0 commit comments

Comments
 (0)