ios: log fatal errors, don't swallow exceptions

This commit is contained in:
Saúl Ibarra Corretgé 2019-09-04 14:11:31 +02:00 committed by Saúl Ibarra Corretgé
parent d4dd5ab46a
commit f2fdef8361
3 changed files with 11 additions and 13 deletions

View File

@ -51,6 +51,9 @@
// Register a fatal error handler for React.
registerReactFatalErrorHandler();
// Register a log handler for React.
registerReactLogHanler();
}
return self;

View File

@ -19,5 +19,6 @@
NSMutableDictionary* mergeProps(NSDictionary *a, NSDictionary *b);
void registerReactFatalErrorHandler(void);
void registerReactLogHandler(void);
#endif /* JM_REACTUTILS_H */

View File

@ -15,7 +15,9 @@
*/
#import <React/RCTAssert.h>
#import <React/RCTLog.h>
#import "LogUtils.h"
#import "ReactUtils.h"
#pragma mark - Utility functions
@ -67,19 +69,11 @@ NSMutableDictionary* mergeProps(NSDictionary *a, NSDictionary *b) {
*/
RCTFatalHandler _RCTFatal = ^(NSError *error) {
id jsStackTrace = error.userInfo[RCTJSStackTraceKey];
@try {
NSString *name
= [NSString stringWithFormat:@"%@: %@",
RCTFatalExceptionName,
error.localizedDescription];
NSString *message
= RCTFormatError(error.localizedDescription, jsStackTrace, 75);
[NSException raise:name format:@"%@", message];
} @catch (NSException *e) {
if (!jsStackTrace) {
@throw;
}
}
NSString *name
= [NSString stringWithFormat:@"%@: %@", RCTFatalExceptionName, error.localizedDescription];
NSString *message
= RCTFormatError(error.localizedDescription, jsStackTrace, -1);
DDLogError(@"FATAL ERROR: %@\n%@", name, message);
};
/**