2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTExceptionsManager.h"
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
#import "RCTConvert.h"
|
2015-04-21 12:26:51 +00:00
|
|
|
#import "RCTDefines.h"
|
2015-04-09 17:39:28 +00:00
|
|
|
#import "RCTLog.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTRedBox.h"
|
2015-04-09 17:39:28 +00:00
|
|
|
#import "RCTRootView.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
@implementation RCTExceptionsManager
|
2015-03-11 20:53:30 +00:00
|
|
|
{
|
|
|
|
__weak id<RCTExceptionsManagerDelegate> _delegate;
|
2015-04-09 17:39:28 +00:00
|
|
|
NSUInteger _reloadRetries;
|
2015-03-11 20:53:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:27:43 +00:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-03-11 20:53:30 +00:00
|
|
|
- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate
|
|
|
|
{
|
2015-11-25 11:09:00 +00:00
|
|
|
if ((self = [self init])) {
|
2015-03-11 20:53:30 +00:00
|
|
|
_delegate = delegate;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-05-13 17:56:09 +00:00
|
|
|
RCT_EXPORT_METHOD(reportSoftException:(NSString *)message
|
2015-11-03 22:45:46 +00:00
|
|
|
stack:(NSDictionaryArray *)stack
|
2015-09-18 01:12:46 +00:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-05-13 17:56:09 +00:00
|
|
|
{
|
2015-11-05 20:19:56 +00:00
|
|
|
[_bridge.redBox showErrorMessage:message withStack:stack];
|
|
|
|
|
2015-05-13 17:56:09 +00:00
|
|
|
if (_delegate) {
|
2015-11-05 20:19:56 +00:00
|
|
|
[_delegate handleSoftJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
2015-05-13 17:56:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
|
2015-11-03 22:45:46 +00:00
|
|
|
stack:(NSDictionaryArray *)stack
|
2015-09-18 01:12:46 +00:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-08-19 12:27:43 +00:00
|
|
|
[_bridge.redBox showErrorMessage:message withStack:stack];
|
2015-04-21 16:48:29 +00:00
|
|
|
|
2015-11-05 20:19:56 +00:00
|
|
|
if (_delegate) {
|
|
|
|
[_delegate handleFatalJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
|
|
|
}
|
2015-04-09 17:39:28 +00:00
|
|
|
|
2015-11-05 20:19:56 +00:00
|
|
|
static NSUInteger reloadRetries = 0;
|
|
|
|
if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) {
|
|
|
|
reloadRetries++;
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil];
|
|
|
|
} else {
|
|
|
|
NSString *description = [@"Unhandled JS Exception: " stringByAppendingString:message];
|
|
|
|
NSDictionary *errorInfo = @{ NSLocalizedDescriptionKey: description, RCTJSStackTraceKey: stack };
|
|
|
|
RCTFatal([NSError errorWithDomain:RCTErrorDomain code:0 userInfo:errorInfo]);
|
2015-03-11 20:53:30 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 15:52:48 +00:00
|
|
|
RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message
|
2015-11-03 22:45:46 +00:00
|
|
|
stack:(NSDictionaryArray *)stack
|
2015-09-18 01:12:46 +00:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-08-19 12:27:43 +00:00
|
|
|
[_bridge.redBox updateErrorMessage:message withStack:stack];
|
2015-11-05 20:19:56 +00:00
|
|
|
|
|
|
|
if (_delegate && [_delegate respondsToSelector:@selector(updateJSExceptionWithMessage:stack:exceptionId:)]) {
|
|
|
|
[_delegate updateJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 17:56:09 +00:00
|
|
|
// Deprecated. Use reportFatalException directly instead.
|
|
|
|
RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
|
2015-11-03 22:45:46 +00:00
|
|
|
stack:(NSDictionaryArray *)stack)
|
2015-05-13 17:56:09 +00:00
|
|
|
{
|
2015-09-18 01:12:46 +00:00
|
|
|
[self reportFatalException:message stack:stack exceptionId:@-1];
|
2015-05-13 17:56:09 +00:00
|
|
|
}
|
2015-11-05 20:19:56 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@end
|