@@ -11,14 +11,14 @@ use crate::api::user::User;
11
11
use super :: { NotificationBatch , NotificationContent } ;
12
12
13
13
/// 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 {
15
15
NotificationBatch {
16
16
badge_count : 0 ,
17
17
removals : Vec :: new ( ) ,
18
18
additions : vec ! [ NotificationContent {
19
19
identifier: "" . to_string( ) ,
20
- title: "Error" . to_string ( ) ,
21
- body: e ,
20
+ title,
21
+ body,
22
22
data: "" . to_string( ) ,
23
23
} ] ,
24
24
}
@@ -32,21 +32,29 @@ pub(crate) fn retrieve_messages_sync(path: String) -> NotificationBatch {
32
32
. build ( )
33
33
. map_err ( |error| {
34
34
error ! ( %error, "Failed to initialize tokio runtime" ) ;
35
- error. to_string ( )
35
+ ( "Runtime error" . to_string ( ) , error . to_string ( ) )
36
36
} )
37
37
. and_then ( |runtime| {
38
38
panic:: catch_unwind ( AssertUnwindSafe ( || {
39
39
runtime. block_on ( async { retrieve_messages ( path) . await } )
40
40
} ) )
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
+ }
44
52
} )
45
53
} ) ;
46
54
47
55
match result {
48
56
Ok ( batch) => batch,
49
- Err ( e ) => error_batch ( e ) ,
57
+ Err ( ( title , body ) ) => error_batch ( title , body ) ,
50
58
}
51
59
}
52
60
@@ -57,11 +65,14 @@ pub(crate) async fn retrieve_messages(path: String) -> NotificationBatch {
57
65
Ok ( Some ( user) ) => user,
58
66
Ok ( None ) => {
59
67
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
+ ) ;
61
72
}
62
73
Err ( error) => {
63
74
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 ( ) ) ;
65
76
}
66
77
} ;
67
78
0 commit comments