Consistently handle startup errors

Summary:
If we use RCTLogError, we show a redbox with a native stacktrace before we can actually show the JS stacktrace (which is only done through dispatch_async). Instead use RCTLogWarn so its logged to console but not reported as a redbox.

Also fix call to RCTNSErrorFromJSErrorRef off the main thread RCTJSCExecutor.

Reviewed By: majak, mmmulani

Differential Revision: D3886813

fbshipit-source-id: 119d04858cb0c85c79e12ff8a79806711f8e0b27
This commit is contained in:
Pieter De Baets 2016-09-20 06:27:32 -07:00 committed by Facebook Github Bot 4
parent c6024f6391
commit 21fda19ca9
2 changed files with 5 additions and 2 deletions

View File

@ -109,6 +109,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
__block NSData *sourceCode; __block NSData *sourceCode;
[self loadSource:^(NSError *error, NSData *source, __unused int64_t sourceLength) { [self loadSource:^(NSError *error, NSData *source, __unused int64_t sourceLength) {
if (error) { if (error) {
RCTLogWarn(@"Failed to load source: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf stopLoadingWithError:error]; [weakSelf stopLoadingWithError:error];
}); });
@ -153,6 +154,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
[weakSelf injectJSONConfiguration:config onComplete:^(NSError *error) { [weakSelf injectJSONConfiguration:config onComplete:^(NSError *error) {
[performanceLogger markStopForTag:RCTPLNativeModuleInjectConfig]; [performanceLogger markStopForTag:RCTPLNativeModuleInjectConfig];
if (error) { if (error) {
RCTLogWarn(@"Failed to inject config: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf stopLoadingWithError:error]; [weakSelf stopLoadingWithError:error];
}); });
@ -502,7 +504,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
} }
if (loadError) { if (loadError) {
RCTLogError(@"Failed to execute source code: %@", [loadError localizedDescription]); RCTLogWarn(@"Failed to execute source code: %@", [loadError localizedDescription]);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self stopLoadingWithError:loadError]; [self stopLoadingWithError:loadError];
}); });

View File

@ -828,8 +828,9 @@ static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleI
jscWrapper->JSStringRelease(sourceURL); jscWrapper->JSStringRelease(sourceURL);
if (!result) { if (!result) {
NSError *error = RCTNSErrorFromJSErrorRef(jsError, ctx, jscWrapper);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
RCTFatal(RCTNSErrorFromJSErrorRef(jsError, ctx, jscWrapper)); RCTFatal(error);
[executor invalidate]; [executor invalidate];
}); });
} }