mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
Improved logging and dev menu
This commit is contained in:
@@ -19,10 +19,6 @@
|
||||
NSUInteger _reloadRetries;
|
||||
}
|
||||
|
||||
#ifndef DEBUG
|
||||
static NSUInteger RCTReloadRetries = 0;
|
||||
#endif
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate
|
||||
@@ -47,27 +43,32 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#if DEBUG
|
||||
|
||||
[[RCTRedBox sharedInstance] showErrorMessage:message withStack:stack];
|
||||
|
||||
#else
|
||||
if (RCTReloadRetries < _maxReloadAttempts) {
|
||||
RCTReloadRetries++;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification object:nil];
|
||||
|
||||
static NSUInteger reloadRetries = 0;
|
||||
const NSUInteger maxMessageLength = 75;
|
||||
|
||||
if (reloadRetries < _maxReloadAttempts) {
|
||||
|
||||
reloadRetries++;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTReloadNotification
|
||||
object:nil];
|
||||
|
||||
} else {
|
||||
NSError *error;
|
||||
const NSUInteger MAX_SANITIZED_LENGTH = 75;
|
||||
|
||||
// Filter out numbers so the same base errors are mapped to the same categories independent of incorrect values.
|
||||
NSString *pattern = @"[+-]?\\d+[,.]?\\d*";
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
|
||||
RCTAssert(error == nil, @"Bad regex pattern: %@", pattern);
|
||||
NSString *sanitizedMessage = [regex stringByReplacingMatchesInString:message
|
||||
options:0
|
||||
range:NSMakeRange(0, message.length)
|
||||
withTemplate:@"<num>"];
|
||||
if (sanitizedMessage.length > MAX_SANITIZED_LENGTH) {
|
||||
sanitizedMessage = [[sanitizedMessage substringToIndex:MAX_SANITIZED_LENGTH] stringByAppendingString:@"..."];
|
||||
NSString *sanitizedMessage = [message stringByReplacingOccurrencesOfString:pattern withString:@"<num>" options:NSRegularExpressionSearch range:(NSRange){0, message.length}];
|
||||
|
||||
if (sanitizedMessage.length > maxMessageLength) {
|
||||
sanitizedMessage = [[sanitizedMessage substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
|
||||
}
|
||||
NSMutableString *prettyStack = [@"\n" mutableCopy];
|
||||
|
||||
NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"];
|
||||
for (NSDictionary *frame in stack) {
|
||||
[prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]];
|
||||
}
|
||||
@@ -75,13 +76,21 @@ RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
|
||||
NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:sanitizedMessage];
|
||||
[NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message
|
||||
stack:(NSArray *)stack)
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
|
||||
[[RCTRedBox sharedInstance] updateErrorMessage:message withStack:stack];
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user