2015-03-23 13:28:42 -07: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-19 20:10:52 -08:00
|
|
|
|
|
|
|
#import "RCTExceptionsManager.h"
|
|
|
|
|
2015-11-03 14:45:46 -08:00
|
|
|
#import "RCTConvert.h"
|
2015-04-21 05:26:51 -07:00
|
|
|
#import "RCTDefines.h"
|
2015-04-09 10:39:28 -07:00
|
|
|
#import "RCTLog.h"
|
2015-02-19 20:10:52 -08:00
|
|
|
#import "RCTRedBox.h"
|
2015-04-09 10:39:28 -07:00
|
|
|
#import "RCTRootView.h"
|
2015-02-19 20:10:52 -08:00
|
|
|
|
|
|
|
@implementation RCTExceptionsManager
|
2015-03-11 13:53:30 -07:00
|
|
|
{
|
|
|
|
__weak id<RCTExceptionsManagerDelegate> _delegate;
|
|
|
|
}
|
|
|
|
|
2015-08-19 11:27:43 -01:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2015-04-08 05:42:43 -07:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-03-11 13:53:30 -07:00
|
|
|
- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate
|
|
|
|
{
|
2015-11-25 03:09:00 -08:00
|
|
|
if ((self = [self init])) {
|
2015-03-11 13:53:30 -07:00
|
|
|
_delegate = delegate;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-05-13 10:56:09 -07:00
|
|
|
RCT_EXPORT_METHOD(reportSoftException:(NSString *)message
|
2015-12-10 10:09:04 -08:00
|
|
|
stack:(NSArray<NSDictionary *> *)stack
|
2015-09-17 18:12:46 -07:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-05-13 10:56:09 -07:00
|
|
|
{
|
2015-11-05 12:19:56 -08:00
|
|
|
[_bridge.redBox showErrorMessage:message withStack:stack];
|
|
|
|
|
2015-05-13 10:56:09 -07:00
|
|
|
if (_delegate) {
|
2015-11-05 12:19:56 -08:00
|
|
|
[_delegate handleSoftJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
2015-05-13 10:56:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
|
2015-12-10 10:09:04 -08:00
|
|
|
stack:(NSArray<NSDictionary *> *)stack
|
2015-09-17 18:12:46 -07:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2015-08-19 11:27:43 -01:00
|
|
|
[_bridge.redBox showErrorMessage:message withStack:stack];
|
2015-04-21 09:48:29 -07:00
|
|
|
|
2015-11-05 12:19:56 -08:00
|
|
|
if (_delegate) {
|
|
|
|
[_delegate handleFatalJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
|
|
|
}
|
2015-04-09 10:39:28 -07:00
|
|
|
|
2015-11-05 12:19:56 -08:00
|
|
|
static NSUInteger reloadRetries = 0;
|
|
|
|
if (!RCT_DEBUG && reloadRetries < _maxReloadAttempts) {
|
|
|
|
reloadRetries++;
|
2016-12-07 16:27:55 -08:00
|
|
|
[_bridge reload];
|
2015-11-05 12:19:56 -08:00
|
|
|
} 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 13:53:30 -07:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
|
2015-04-08 08:52:48 -07:00
|
|
|
RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message
|
2015-12-10 10:09:04 -08:00
|
|
|
stack:(NSArray<NSDictionary *> *)stack
|
2015-09-17 18:12:46 -07:00
|
|
|
exceptionId:(nonnull NSNumber *)exceptionId)
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
2015-08-19 11:27:43 -01:00
|
|
|
[_bridge.redBox updateErrorMessage:message withStack:stack];
|
2015-11-05 12:19:56 -08:00
|
|
|
|
|
|
|
if (_delegate && [_delegate respondsToSelector:@selector(updateJSExceptionWithMessage:stack:exceptionId:)]) {
|
|
|
|
[_delegate updateJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
|
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
|
2015-05-13 10:56:09 -07:00
|
|
|
// Deprecated. Use reportFatalException directly instead.
|
|
|
|
RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
|
2015-12-10 10:09:04 -08:00
|
|
|
stack:(NSArray<NSDictionary *> *)stack)
|
2015-05-13 10:56:09 -07:00
|
|
|
{
|
2015-09-17 18:12:46 -07:00
|
|
|
[self reportFatalException:message stack:stack exceptionId:@-1];
|
2015-05-13 10:56:09 -07:00
|
|
|
}
|
2015-11-05 12:19:56 -08:00
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
@end
|