Skip to content

Commit

Permalink
[skip ci] earlyjs: Integrate c++ pipeline with all ios apps
Browse files Browse the repository at this point in the history
Summary:
Now, all ios apps will just be integrated with the c++ error reporting pipeline, with zero configuration.

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D64615457
  • Loading branch information
RSNara authored and facebook-github-bot committed Oct 25, 2024
1 parent 94f221c commit e34fcb0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 134 deletions.
12 changes: 0 additions & 12 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,6 @@ - (void)hostDidStart:(RCTHost *)host
{
}

- (void)host:(RCTHost *)host
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
message:(NSString *)message
originalMessage:(NSString *_Nullable)originalMessage
name:(NSString *_Nullable)name
componentStack:(NSString *_Nullable)componentStack
exceptionId:(NSUInteger)exceptionId
isFatal:(BOOL)isFatal
extraData:(NSDictionary<NSString *, id> *)extraData
{
}

#pragma mark - Bridge and Bridge Adapter properties

- (RCTBridge *)bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)reportFatalException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId;
- (void)reportJsException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId
isFatal:(bool)isFatal;

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

Expand Down
12 changes: 0 additions & 12 deletions packages/react-native/React/CoreModules/RCTExceptionsManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ - (void)reportFatal:(NSString *)message
}
}

- (void)reportJsException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId
isFatal:(bool)isFatal
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,51 +115,6 @@ - (void)testCallFunctionOnJSModule
XCTAssertEqualObjects(shimmedRCTInstance.args, args);
}

- (void)testDidReceiveErrorStack
{
id<RCTInstanceDelegate> instanceDelegate = (id<RCTInstanceDelegate>)_subject;

NSMutableArray<NSDictionary<NSString *, id> *> *stack = [NSMutableArray array];

NSMutableDictionary<NSString *, id> *stackFrame0 = [NSMutableDictionary dictionary];
stackFrame0[@"linenumber"] = @(3);
stackFrame0[@"column"] = @(4);
stackFrame0[@"methodname"] = @"method1";
stackFrame0[@"file"] = @"file1.js";
[stack addObject:stackFrame0];

NSMutableDictionary<NSString *, id> *stackFrame1 = [NSMutableDictionary dictionary];
stackFrame0[@"linenumber"] = @(63);
stackFrame0[@"column"] = @(44);
stackFrame0[@"methodname"] = @"method2";
stackFrame0[@"file"] = @"file2.js";
[stack addObject:stackFrame1];

id extraData = [NSDictionary dictionary];

[instanceDelegate instance:[OCMArg any]
didReceiveJSErrorStack:stack
message:@"message"
originalMessage:nil
name:nil
componentStack:nil
exceptionId:5
isFatal:YES
extraData:extraData];

OCMVerify(
OCMTimes(1),
[_mockHostDelegate host:_subject
didReceiveJSErrorStack:stack
message:@"message"
originalMessage:nil
name:nil
componentStack:nil
exceptionId:5
isFatal:YES
extraData:extraData]);
}

- (void)testDidInitializeRuntime
{
id<RCTHostRuntimeDelegate> mockRuntimeDelegate = OCMProtocolMock(@protocol(RCTHostRuntimeDelegate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ folly_version = folly_config[:version]
folly_dep_name = folly_config[:dep_name]

boost_config = get_boost_config()
boost_compiler_flags = boost_config[:compiler_flags]
boost_compiler_flags = boost_config[:compiler_flags]

header_search_paths = [
"$(PODS_ROOT)/boost",
Expand Down Expand Up @@ -70,6 +70,8 @@ Pod::Spec.new do |s|
s.dependency "React-jserrorhandler"
s.dependency "React-jsinspector"

add_dependency(s, "ReactCodegen")

if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
s.dependency "hermes-engine"
s.dependency "React-RuntimeHermes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ typedef NSURL *_Nullable (^RCTHostBundleURLProvider)(void);

@protocol RCTHostDelegate <NSObject>

- (void)host:(RCTHost *)host
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
message:(NSString *)message
originalMessage:(NSString *_Nullable)originalMessage
name:(NSString *_Nullable)name
componentStack:(NSString *_Nullable)componentStack
exceptionId:(NSUInteger)exceptionId
isFatal:(BOOL)isFatal
extraData:(NSDictionary<NSString *, id> *)extraData;

- (void)hostDidStart:(RCTHost *)host;

@optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,6 @@ - (void)dealloc

#pragma mark - RCTInstanceDelegate

- (void)instance:(RCTInstance *)instance
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
message:(NSString *)message
originalMessage:(NSString *_Nullable)originalMessage
name:(NSString *_Nullable)name
componentStack:(NSString *_Nullable)componentStack
exceptionId:(NSUInteger)exceptionId
isFatal:(BOOL)isFatal
extraData:(NSDictionary<NSString *, id> *)extraData
{
[_hostDelegate host:self
didReceiveJSErrorStack:stack
message:message
originalMessage:originalMessage
name:name
componentStack:componentStack
exceptionId:exceptionId
isFatal:isFatal
extraData:extraData];
}

- (void)instance:(RCTInstance *)instance didInitializeRuntime:(facebook::jsi::Runtime &)runtime
{
[self.runtimeDelegate host:self didInitializeRuntime:runtime];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags);

@protocol RCTInstanceDelegate <RCTContextContainerHandling>

- (void)instance:(RCTInstance *)instance
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
message:(NSString *)message
originalMessage:(NSString *_Nullable)originalMessage
name:(NSString *_Nullable)name
componentStack:(NSString *_Nullable)componentStack
exceptionId:(NSUInteger)exceptionId
isFatal:(BOOL)isFatal
extraData:(NSDictionary<NSString *, id> *)extraData;

- (void)instance:(RCTInstance *)instance didInitializeRuntime:(facebook::jsi::Runtime &)runtime;

- (void)loadBundleAtURL:(NSURL *)sourceURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <memory>

#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/NSDataBigString.h>
#import <React/RCTAssert.h>
#import <React/RCTBridge+Inspector.h>
Expand Down Expand Up @@ -467,32 +468,47 @@ - (void)_loadScriptFromSource:(RCTSource *)source

- (void)_handleJSError:(const JsErrorHandler::ParsedError &)error withRuntime:(jsi::Runtime &)runtime
{
NSString *message = @(error.message.c_str());
NSMutableDictionary *errorData = [NSMutableDictionary new];
errorData[@"message"] = @(error.message.c_str());
if (error.originalMessage) {
errorData[@"originalMessage"] = @(error.originalMessage->c_str());
}
if (error.name) {
errorData[@"name"] = @(error.name->c_str());
}
if (error.componentStack) {
errorData[@"componentStack"] = @(error.componentStack->c_str());
}

NSMutableArray<NSDictionary<NSString *, id> *> *stack = [NSMutableArray new];
for (const JsErrorHandler::ParsedError::StackFrame &frame : error.stack) {
[stack addObject:@{
@"file" : frame.file ? @((*frame.file).c_str()) : [NSNull null],
@"methodName" : @(frame.methodName.c_str()),
@"lineNumber" : frame.lineNumber ? @(*frame.lineNumber) : [NSNull null],
@"column" : frame.column ? @(*frame.column) : [NSNull null],
}];
NSMutableDictionary<NSString *, id> *stackFrame = [NSMutableDictionary new];
if (frame.file) {
stackFrame[@"file"] = @(frame.file->c_str());
}
stackFrame[@"methodName"] = @(frame.methodName.c_str());
if (frame.lineNumber) {
stackFrame[@"lineNumber"] = @(*frame.lineNumber);
}
if (frame.column) {
stackFrame[@"column"] = @(*frame.column);
}
[stack addObject:stackFrame];
}

NSString *originalMessage = error.originalMessage ? @(error.originalMessage->c_str()) : nil;
NSString *name = error.name ? @(error.name->c_str()) : nil;
NSString *componentStack = error.componentStack ? @(error.componentStack->c_str()) : nil;
errorData[@"stack"] = stack;
errorData[@"id"] = @(error.id);
errorData[@"isFatal"] = @(error.isFatal);

id extraData =
TurboModuleConvertUtils::convertJSIValueToObjCObject(runtime, jsi::Value(runtime, error.extraData), nullptr);
if (extraData) {
errorData[@"extraData"] = extraData;
}

[_delegate instance:self
didReceiveJSErrorStack:stack
message:message
originalMessage:originalMessage
name:name
componentStack:componentStack
exceptionId:error.id
isFatal:error.isFatal
extraData:extraData];
JS::NativeExceptionsManager::ExceptionData jsErrorData{errorData};
id<NativeExceptionsManagerSpec> exceptionsManager = [_turboModuleManager moduleForName:"ExceptionsManager"];
[exceptionsManager reportException:jsErrorData];
}

@end

0 comments on commit e34fcb0

Please sign in to comment.