|
12 | 12 | NSString *const RCTJSStackTraceKey = @"RCTJSStackTraceKey";
|
13 | 13 | NSString *const RCTJSRawStackTraceKey = @"RCTJSRawStackTraceKey";
|
14 | 14 | NSString *const RCTFatalExceptionName = @"RCTFatalException";
|
| 15 | +NSString *const RCTUntruncatedMessageKey = @"RCTUntruncatedMessageKey"; |
15 | 16 |
|
16 | 17 | static NSString *const RCTAssertFunctionStack = @"RCTAssertFunctionStack";
|
17 | 18 |
|
@@ -128,8 +129,20 @@ void RCTFatal(NSError *error)
|
128 | 129 | @try {
|
129 | 130 | #endif
|
130 | 131 | NSString *name = [NSString stringWithFormat:@"%@: %@", RCTFatalExceptionName, error.localizedDescription];
|
131 |
| - NSString *message = RCTFormatError(error.localizedDescription, error.userInfo[RCTJSStackTraceKey], 75); |
132 |
| - @throw [[NSException alloc] initWithName:name reason:message userInfo:nil]; |
| 132 | + |
| 133 | + // Truncate the localized description to 175 characters to avoid wild screen overflows |
| 134 | + NSString *message = RCTFormatError(error.localizedDescription, error.userInfo[RCTJSStackTraceKey], 175); |
| 135 | + |
| 136 | + // Attach an untruncated copy of the description to the userInfo, in case it is needed |
| 137 | + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; |
| 138 | + [userInfo setObject:RCTFormatError(error.localizedDescription, error.userInfo[RCTJSStackTraceKey], -1) |
| 139 | + forKey:RCTUntruncatedMessageKey]; |
| 140 | + |
| 141 | + // Expected resulting exception information: |
| 142 | + // name: RCTFatalException: <underlying error description> |
| 143 | + // reason: <underlying error description plus JS stack trace, truncated to 175 characters> |
| 144 | + // userInfo: <underlying error userinfo, plus untruncated description plus JS stack trace> |
| 145 | + @throw [[NSException alloc] initWithName:name reason:message userInfo:userInfo]; |
133 | 146 | #if DEBUG
|
134 | 147 | } @catch (NSException *e) {}
|
135 | 148 | #endif
|
|
0 commit comments