From 21fda19ca9bc15eae8781b0095673d0be70d9ff7 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 20 Sep 2016 06:27:32 -0700 Subject: [PATCH] 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 --- React/Base/RCTBatchedBridge.m | 4 +++- React/Executors/RCTJSCExecutor.mm | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 952e748c8..443c57833 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -109,6 +109,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id)dele __block NSData *sourceCode; [self loadSource:^(NSError *error, NSData *source, __unused int64_t sourceLength) { if (error) { + RCTLogWarn(@"Failed to load source: %@", error); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf stopLoadingWithError:error]; }); @@ -153,6 +154,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id)dele [weakSelf injectJSONConfiguration:config onComplete:^(NSError *error) { [performanceLogger markStopForTag:RCTPLNativeModuleInjectConfig]; if (error) { + RCTLogWarn(@"Failed to inject config: %@", error); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf stopLoadingWithError:error]; }); @@ -502,7 +504,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id)dele } if (loadError) { - RCTLogError(@"Failed to execute source code: %@", [loadError localizedDescription]); + RCTLogWarn(@"Failed to execute source code: %@", [loadError localizedDescription]); dispatch_async(dispatch_get_main_queue(), ^{ [self stopLoadingWithError:loadError]; }); diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index c8f6702c3..09f83a117 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -828,8 +828,9 @@ static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleI jscWrapper->JSStringRelease(sourceURL); if (!result) { + NSError *error = RCTNSErrorFromJSErrorRef(jsError, ctx, jscWrapper); dispatch_async(dispatch_get_main_queue(), ^{ - RCTFatal(RCTNSErrorFromJSErrorRef(jsError, ctx, jscWrapper)); + RCTFatal(error); [executor invalidate]; }); }