11import  Foundation
22/**
3-  * Handler
3+  * - Note: Do not attempt to make network requests here, as the app is unstable
4+  */
5+ func  handleException( _ exception:  NSException )  { 
6+    let  crashLog :  [ String :  String ]  =  createCrashLog ( from:  exception) 
7+    saveCrashReport ( crashLog) 
8+ } 
9+ /**
10+  * - Fixme: ⚠️️ add doc
11+  */
12+ func  handleSignal( _ signal:  Int32 )  { 
13+    let  crashLog :  [ String :  String ]  =  createCrashLog ( from:  signal) 
14+    saveCrashReport ( crashLog) 
15+ } 
16+ /**
17+  * - Fixme: ⚠️️ add doc
18+  * - Fixme: ⚠️️ we can unpack more info here. see issue tracker for more info
19+  */
20+ func  createCrashLog( from signal:  Int32 )  ->  [ String :  String ]  { 
21+    #if DEBUG 
22+    if  isDebug {  Swift . print ( " createCrashLog(signal:) " )  } 
23+    #endif 
24+    let  crashLog  =  [ 
25+       " Signal " :  " \( signal) " , 
26+       " reason " :  " \( Date ( ) ) " , 
27+    ] 
28+    // Note: Save the crash details locally (e.g., in UserDefaults or a file)
29+    return  crashLog
30+ } 
31+ /**
432 * - Note: must be global function, due to c-pointer limitations
533 * - Note: Function to create crash log
634 */
7- internal  func  exceptionHandler( from exception:  NSException )  ->  [ String :  String ]  { 
35+ internal  func  createCrashLog( from exception:  NSException )  ->  [ String :  String ]  { 
36+    #if DEBUG 
37+    if  isDebug {  Swift . print ( " createCrashLog(exception:) " )  } 
38+    #endif 
839   let  crashLog  =  [ 
940      " name " :  " \( exception. name. rawValue) " , 
1041      " reason " :  " \( exception. reason ??  " No reason provided " ) " , 
@@ -15,24 +46,6 @@ internal func exceptionHandler(from exception: NSException) -> [String: String]
1546   // Note: Save the crash details locally (e.g., in UserDefaults or a file)
1647   return  crashLog
1748} 
18- 
19- /**
20-  * Handle signals
21-  */
22- internal  func  handleSignal( )  { 
23-    #if DEBUG 
24-    if  isDebug {  Swift . print ( " handleSignal " )  } 
25-    #endif 
26-    let  crashLog :  [ String :  String ]  =  exceptionHandler ( 
27-       from:  NSException ( 
28-          name:  NSExceptionName ( rawValue:  " Critical Argument Error " ) , 
29-          reason:  " Unhandled signal " , 
30-          userInfo:  nil 
31-       ) 
32-    ) 
33-    saveCrashReport ( crashLog) 
34-    // Note: Do not attempt to make network requests here, as the app is unstable
35- } 
3649/**
3750 * File
3851 */
0 commit comments