[ReactNative] Add JS errors handling to iOS
Summary: Every once in a while a guard is forgotten somewhere and the redbox is gone. I want to remove the guards, but for that the stack traces have to be symbolicated on the native side. So for now it just adds yet another check, in case a guard is missing on JS.
This commit is contained in:
parent
2e9d156fad
commit
9799c215cb
|
@ -239,7 +239,11 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
||||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||||
[_javaScriptExecutor injectJSONText:configJSON
|
[_javaScriptExecutor injectJSONText:configJSON
|
||||||
asGlobalObjectNamed:@"__fbBatchedBridgeConfig" callback:
|
asGlobalObjectNamed:@"__fbBatchedBridgeConfig" callback:
|
||||||
^(__unused id err) {
|
^(NSError *error) {
|
||||||
|
if (error) {
|
||||||
|
[[RCTRedBox sharedInstance] showError:error];
|
||||||
|
}
|
||||||
|
|
||||||
dispatch_semaphore_signal(semaphore);
|
dispatch_semaphore_signal(semaphore);
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
@ -302,22 +306,21 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
||||||
|
|
||||||
[self enqueueApplicationScript:script url:bundleURL onComplete:^(NSError *loadError) {
|
[self enqueueApplicationScript:script url:bundleURL onComplete:^(NSError *loadError) {
|
||||||
|
|
||||||
if (!loadError) {
|
if (loadError) {
|
||||||
|
[[RCTRedBox sharedInstance] showError:loadError];
|
||||||
/**
|
return;
|
||||||
* Register the display link to start sending js calls after everything
|
|
||||||
* is setup
|
|
||||||
*/
|
|
||||||
NSRunLoop *targetRunLoop = [_javaScriptExecutor isKindOfClass:[RCTContextExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop];
|
|
||||||
[_jsDisplayLink addToRunLoop:targetRunLoop forMode:NSRunLoopCommonModes];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
|
|
||||||
object:_parentBridge
|
|
||||||
userInfo:@{ @"bridge": self }];
|
|
||||||
} else {
|
|
||||||
[[RCTRedBox sharedInstance] showErrorMessage:[loadError localizedDescription]
|
|
||||||
withDetails:[loadError localizedFailureReason]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the display link to start sending js calls after everything
|
||||||
|
* is setup
|
||||||
|
*/
|
||||||
|
NSRunLoop *targetRunLoop = [_javaScriptExecutor isKindOfClass:[RCTContextExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop];
|
||||||
|
[_jsDisplayLink addToRunLoop:targetRunLoop forMode:NSRunLoopCommonModes];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
|
||||||
|
object:_parentBridge
|
||||||
|
userInfo:@{ @"bridge": self }];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
@ -527,7 +530,11 @@ RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTEnqueueNotification object:nil userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTEnqueueNotification object:nil userInfo:nil];
|
||||||
|
|
||||||
RCTJavaScriptCallback processResponse = ^(id json, __unused NSError *error) {
|
RCTJavaScriptCallback processResponse = ^(id json, NSError *error) {
|
||||||
|
if (error) {
|
||||||
|
[[RCTRedBox sharedInstance] showError:error];
|
||||||
|
}
|
||||||
|
|
||||||
if (!self.isValid) {
|
if (!self.isValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
+ (instancetype)sharedInstance;
|
+ (instancetype)sharedInstance;
|
||||||
|
|
||||||
|
- (void)showError:(NSError *)error;
|
||||||
- (void)showErrorMessage:(NSString *)message;
|
- (void)showErrorMessage:(NSString *)message;
|
||||||
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details;
|
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details;
|
||||||
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack;
|
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack;
|
||||||
|
|
|
@ -283,6 +283,11 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
|
||||||
_nextBackgroundColor = color;
|
_nextBackgroundColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)showError:(NSError *)error
|
||||||
|
{
|
||||||
|
[self showErrorMessage:error.localizedDescription withDetails:error.localizedFailureReason];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)showErrorMessage:(NSString *)message
|
- (void)showErrorMessage:(NSString *)message
|
||||||
{
|
{
|
||||||
[self showErrorMessage:message withStack:nil showIfHidden:YES];
|
[self showErrorMessage:message withStack:nil showIfHidden:YES];
|
||||||
|
@ -342,6 +347,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
|
||||||
@implementation RCTRedBox
|
@implementation RCTRedBox
|
||||||
|
|
||||||
+ (instancetype)sharedInstance { return nil; }
|
+ (instancetype)sharedInstance { return nil; }
|
||||||
|
- (void)showError:(NSError *)message {}
|
||||||
- (void)showErrorMessage:(NSString *)message {}
|
- (void)showErrorMessage:(NSString *)message {}
|
||||||
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details {}
|
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details {}
|
||||||
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
|
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
|
||||||
|
|
Loading…
Reference in New Issue