Skip to content

Commit

Permalink
Hook EarlyJsErrorHandler
Browse files Browse the repository at this point in the history
Summary:
Hoop up EarlyJsErrorHandler so we could pass js error data to object-c to report.

Changelog:
[iOS][Chagned] - Add function to report early js errors

Reviewed By: RSNara

Differential Revision: D34096343

fbshipit-source-id: fdbc6ea5d1f3cc6ab55fcd22b48bbe8fb1f1ca8f
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Mar 10, 2022
1 parent 325be42 commit 1804951
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion React/CoreModules/RCTExceptionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>
#import <string>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)reportFatalException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId;
- (void)reportEarlyJsException:(std::string)errorMap;

@property (nonatomic, weak) id<RCTExceptionsManagerDelegate> delegate;

Expand Down
21 changes: 21 additions & 0 deletions React/CoreModules/RCTExceptionsManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ - (void)reportFatal:(NSString *)message stack:(NSArray<NSDictionary *> *)stack e
}
}

- (void)reportEarlyJsException:(std::string)errorMap
{
NSString *errprStr = [NSString stringWithUTF8String:errorMap.c_str()];
NSData *jsonData = [errprStr dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONWritingPrettyPrinted
error:&jsonError];

NSString *message = [dict objectForKey:@"message"];
double exceptionId = [[dict objectForKey:@"id"] doubleValue];
NSArray *stack = [dict objectForKey:@"stack"];
BOOL isFatal = [[dict objectForKey:@"isFatal"] boolValue];

if (isFatal) {
[self reportFatalException:message stack:stack exceptionId:exceptionId];
} else {
[self reportSoftException:message stack:stack exceptionId:exceptionId];
}
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
Expand Down

0 comments on commit 1804951

Please sign in to comment.