From 47164baaec01d4791d15db6ef5d4c5f94923e35e Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Wed, 6 May 2015 17:23:57 -0700 Subject: [PATCH] Fixed redbox error loop when camera access is disabled --- React/Base/RCTBridge.m | 16 ++++----- React/Modules/RCTExceptionsManager.m | 53 +++++++++++++--------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index a7c6a30a6..fd3ecaa24 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -1495,17 +1495,13 @@ RCT_BRIDGE_WARN(_invokeAndProcessModule:(NSString *)module method:(NSString *)me return; } - if (!RCT_DEBUG) { + @try { [method invokeWithBridge:strongSelf module:module arguments:params context:context]; - } else { - @try { - [method invokeWithBridge:strongSelf module:module arguments:params context:context]; - } - @catch (NSException *exception) { - RCTLogError(@"Exception thrown while invoking %@ on target %@ with params %@: %@", method.JSMethodName, module, params, exception); - if ([exception.name rangeOfString:@"Unhandled JS Exception"].location != NSNotFound) { - @throw; - } + } + @catch (NSException *exception) { + RCTLogError(@"Exception thrown while invoking %@ on target %@ with params %@: %@", method.JSMethodName, module, params, exception); + if (!RCT_DEBUG && [exception.name rangeOfString:@"Unhandled JS Exception"].location != NSNotFound) { + @throw exception; } } diff --git a/React/Modules/RCTExceptionsManager.m b/React/Modules/RCTExceptionsManager.m index f391e6af0..ddea1275a 100644 --- a/React/Modules/RCTExceptionsManager.m +++ b/React/Modules/RCTExceptionsManager.m @@ -44,50 +44,45 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message return; } -#if RCT_DEBUG // Red box is only available in debug mode - [[RCTRedBox sharedInstance] showErrorMessage:message withStack:stack]; -#else + if (!RCT_DEBUG) { - static NSUInteger reloadRetries = 0; - const NSUInteger maxMessageLength = 75; + static NSUInteger reloadRetries = 0; + const NSUInteger maxMessageLength = 75; - if (reloadRetries < _maxReloadAttempts) { + if (reloadRetries < _maxReloadAttempts) { - reloadRetries++; - [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification - object:nil]; + reloadRetries++; + [[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification + object:nil]; - } else { + } else { - if (message.length > maxMessageLength) { - message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."]; + if (message.length > maxMessageLength) { + message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."]; + } + + NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"]; + for (NSDictionary *frame in stack) { + [prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]]; + } + + NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:message]; + [NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack]; } - - NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"]; - for (NSDictionary *frame in stack) { - [prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]]; - } - - NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:message]; - [NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack]; } - -#endif - } RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message stack:(NSArray *)stack) { + if (_delegate) { + [_delegate unhandledJSExceptionWithMessage:message stack:stack]; + return; + } -#if RCT_DEBUG // Red box is only available in debug mode - - [[RCTRedBox sharedInstance] updateErrorMessage:message withStack:stack]; - -#endif - + [[RCTRedBox sharedInstance] updateErrorMessage:message withStack:stack]; } @end