More verbose error messages for iOS
Summary: Output the reason for the error when failing to load source code. This was a big help when trying to diagnose https://github.com/facebook/react-native/issues/13299. ~~Unfortunately there still seems to be no way to get the offending line number (because `loadError.userInfo[RCTJSStackTraceKey]` is empty), but this is good enough.~~ Before: ``` [warn][tid:com.facebook.react.JavaScript][RCTBatchedBridge.m:510] Failed to execute source code. Unhandled JS Exception: SyntaxError ``` After: ``` [warn][tid:com.facebook.react.JavaScript][RCTJSCErrorHandling.mm:30] Couldn't get stack trace for http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:81886 [warn][tid:com.facebook.react.JavaScript][RCTBatchedBridge.m:510] Failed to execute source code. Unhandled JS Exception: SyntaxError Unexpected keyword 'var' ``` Closes https://github.com/facebook/react-native/pull/13561 Differential Revision: D4908501 Pulled By: javache fbshipit-source-id: a316dc70739b917b3cc690309d0ff37a8bb5d412
This commit is contained in:
parent
cc4648ba86
commit
e443b7379e
|
@ -210,7 +210,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||||
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
|
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
|
||||||
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:self->_parentBridge];
|
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:self->_parentBridge];
|
||||||
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
|
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
|
||||||
RCTLogError(@"Failed to load bundle(%@) with error:(%@)", self.bundleURL, error.localizedDescription);
|
RCTLogError(@"Failed to load bundle(%@) with error:(%@ %@)", self.bundleURL, error.localizedDescription, error.localizedFailureReason);
|
||||||
self.bundleURL = fallbackURL;
|
self.bundleURL = fallbackURL;
|
||||||
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onProgress:onProgress onComplete:onSourceLoad];
|
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onProgress:onProgress onComplete:onSourceLoad];
|
||||||
return;
|
return;
|
||||||
|
@ -513,7 +513,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadError) {
|
if (loadError) {
|
||||||
RCTLogWarn(@"Failed to execute source code: %@", [loadError localizedDescription]);
|
RCTLogWarn(@"Failed to execute source code: %@ %@", [loadError localizedDescription], [loadError localizedFailureReason]);
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self stopLoadingWithError:loadError];
|
[self stopLoadingWithError:loadError];
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#import "RCTAssert.h"
|
#import "RCTAssert.h"
|
||||||
#import "RCTJSStackFrame.h"
|
#import "RCTJSStackFrame.h"
|
||||||
|
#import "RCTLog.h"
|
||||||
|
|
||||||
NSString *const RCTJSExceptionUnsymbolicatedStackTraceKey = @"RCTJSExceptionUnsymbolicatedStackTraceKey";
|
NSString *const RCTJSExceptionUnsymbolicatedStackTraceKey = @"RCTJSExceptionUnsymbolicatedStackTraceKey";
|
||||||
|
|
||||||
|
@ -25,7 +26,9 @@ NSError *RCTNSErrorFromJSError(JSValue *exception)
|
||||||
userInfo[NSLocalizedFailureReasonErrorKey] = exceptionMessage;
|
userInfo[NSLocalizedFailureReasonErrorKey] = exceptionMessage;
|
||||||
}
|
}
|
||||||
NSString *const stack = [exception[@"stack"] toString];
|
NSString *const stack = [exception[@"stack"] toString];
|
||||||
if ([stack length]) {
|
if ([@"undefined" isEqualToString:stack]) {
|
||||||
|
RCTLogWarn(@"Couldn't get stack trace for %@:%@", exception[@"sourceURL"], exception[@"line"]);
|
||||||
|
} else if ([stack length]) {
|
||||||
NSArray<RCTJSStackFrame *> *const unsymbolicatedFrames = [RCTJSStackFrame stackFramesWithLines:stack];
|
NSArray<RCTJSStackFrame *> *const unsymbolicatedFrames = [RCTJSStackFrame stackFramesWithLines:stack];
|
||||||
userInfo[RCTJSStackTraceKey] = unsymbolicatedFrames;
|
userInfo[RCTJSStackTraceKey] = unsymbolicatedFrames;
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,7 @@ struct RCTInstanceCallback : public InstanceCallback {
|
||||||
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
|
if (error && [self.delegate respondsToSelector:@selector(fallbackSourceURLForBridge:)]) {
|
||||||
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:self->_parentBridge];
|
NSURL *fallbackURL = [self.delegate fallbackSourceURLForBridge:self->_parentBridge];
|
||||||
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
|
if (fallbackURL && ![fallbackURL isEqual:self.bundleURL]) {
|
||||||
RCTLogError(@"Failed to load bundle(%@) with error:(%@)", self.bundleURL, error.localizedDescription);
|
RCTLogError(@"Failed to load bundle(%@) with error:(%@ %@)", self.bundleURL, error.localizedDescription, error.localizedFailureReason);
|
||||||
self.bundleURL = fallbackURL;
|
self.bundleURL = fallbackURL;
|
||||||
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onProgress:onProgress onComplete:onSourceLoad];
|
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onProgress:onProgress onComplete:onSourceLoad];
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue