Skip to content

Commit 61d6935

Browse files
javachefacebook-github-bot
authored andcommitted
Move ErrorUtils from cxxreact to jserrorhandler (#57236)
Summary: Move `handleJSError` from `cxxreact/ErrorUtils.h` (header-inline) to `jserrorhandler/ErrorUtils.{h,cpp}` (declared + linked). Inverts the cyclic dep so `jserrorhandler` becomes a standalone leaf and `cxxreact:bridge` can be narrowed out of more consumers in follow-ups. The old `<cxxreact/ErrorUtils.h>` include path continues to work via a deprecated `#warning` forwarder header that includes the new location. `cxxreact:bridge` now depends on `jserrorhandler:jserrorhandler` so existing consumers of the deprecated path still link cleanly. `jserrorhandler/BUCK` drops its `cxxreact:bridge` dep (and the matching `React-cxxreact` podspec entry). Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D108786498
1 parent 9ab5dd8 commit 61d6935

24 files changed

Lines changed: 90 additions & 54 deletions

packages/react-native/Package.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ let reactCxxReact = RNTarget(
198198
path: "ReactCommon/cxxreact",
199199
searchPaths: [CallInvokerPath],
200200
excludedPaths: ["tests"],
201-
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .logger, .reactDebug, .reactJsInspector]
201+
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .logger, .reactDebug, .reactJsErrorHandler, .reactJsInspector]
202202
)
203203

204204
/// React-jsitooling.podspec
@@ -271,14 +271,6 @@ let reactTurboModuleBridging = RNTarget(
271271
dependencies: [.reactNativeDependencies, .reactPerfLogger, .reactCxxReact, .jsi, .logger]
272272
)
273273

274-
/// React-jserrorhandler.podspec
275-
let reactJsErrorHandler = RNTarget(
276-
name: .reactJsErrorHandler,
277-
path: "ReactCommon/jserrorhandler",
278-
excludedPaths: ["tests"],
279-
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
280-
)
281-
282274
/// React-graphicsApple
283275
/// This represents the React-graphicsApple BUCK module
284276
let reactGraphicsApple = RNTarget(
@@ -307,7 +299,7 @@ let reactTurboModuleCore = RNTarget(
307299
"ReactCommon/react/nativemodule/core/platform/ios",
308300
],
309301
excludedPaths: ["platform/android", "iostests"],
310-
dependencies: [.reactNativeDependencies, .reactDebug, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
302+
dependencies: [.reactNativeDependencies, .reactDebug, .reactJsErrorHandler, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
311303
)
312304

313305
/// React-defaultsnativemodule.podspec
@@ -396,6 +388,14 @@ let reactCoreModules = RNTarget(
396388
dependencies: [.reactNativeDependencies, .jsi, .yoga, .reactTurboModuleCore, .reactFeatureFlags]
397389
)
398390

391+
/// React-jserrorhandler.podspec
392+
let reactJsErrorHandler = RNTarget(
393+
name: .reactJsErrorHandler,
394+
path: "ReactCommon/jserrorhandler",
395+
excludedPaths: ["tests"],
396+
dependencies: [.reactNativeDependencies, .jsi, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
397+
)
398+
399399
/// React-runtimeCore.podspec
400400
/// React-runtimeHermes.podspec
401401
let reactRuntime = RNTarget(

packages/react-native/ReactCommon/ReactCommon.podspec

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Pod::Spec.new do |s|
4343
s.subspec "turbomodule" do |ss|
4444
ss.dependency "React-callinvoker", version
4545
ss.dependency "React-perflogger", version
46-
ss.dependency "React-cxxreact", version
4746
ss.dependency "React-jsi", version
4847
ss.dependency "React-logger", version
4948
if use_hermes()
@@ -56,14 +55,12 @@ Pod::Spec.new do |s|
5655
sss.exclude_files = "react/bridging/tests"
5756
sss.header_dir = "react/bridging"
5857
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\"" }
59-
if use_hermes()
60-
sss.dependency "hermes-engine"
61-
end
6258
end
6359

6460
ss.subspec "core" do |sss|
6561
sss.source_files = podspec_sources("react/nativemodule/core/ReactCommon/**/*.{cpp,h}", "react/nativemodule/core/ReactCommon/**/*.h")
6662
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_featureflags.framework/Headers\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-utils/React_utils.framework/Headers\"" }
63+
sss.dependency "React-cxxreact", version
6764
sss.dependency "React-debug", version
6865
sss.dependency "React-featureflags", version
6966
sss.dependency "React-utils", version

packages/react-native/ReactCommon/cxxreact/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_link_libraries(react_cxxreact
1818
callinvoker
1919
folly_runtime
2020
glog
21+
jserrorhandler
2122
jsi
2223
jsinspector
2324
logger

packages/react-native/ReactCommon/cxxreact/ErrorUtils.h

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,6 @@
77

88
#pragma once
99

10-
#include <jsi/jsi.h>
10+
#warning Deprecated: use <jserrorhandler/ErrorUtils.h> instead.
1111

12-
namespace facebook::react {
13-
14-
inline static void handleJSError(jsi::Runtime &runtime, const jsi::JSError &error, bool isFatal)
15-
{
16-
auto errorUtils = runtime.global().getProperty(runtime, "ErrorUtils");
17-
if (errorUtils.isUndefined() || !errorUtils.isObject() ||
18-
!errorUtils.getObject(runtime).hasProperty(runtime, "reportFatalError") ||
19-
!errorUtils.getObject(runtime).hasProperty(runtime, "reportError")) {
20-
// ErrorUtils was not set up. This probably means the bundle didn't
21-
// load properly.
22-
throw jsi::JSError(
23-
runtime,
24-
"ErrorUtils is not set up properly. Something probably went wrong trying to load the JS bundle. Trying to report error " +
25-
error.getMessage(),
26-
error.getStack());
27-
}
28-
29-
// TODO(janzer): Rewrite this function to return the processed error
30-
// instead of just reporting it through the native module
31-
if (isFatal) {
32-
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(runtime, "reportFatalError");
33-
34-
func.call(runtime, error.value());
35-
} else {
36-
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(runtime, "reportError");
37-
38-
func.call(runtime, error.value());
39-
}
40-
}
41-
42-
} // namespace facebook::react
12+
#include <jserrorhandler/ErrorUtils.h>

packages/react-native/ReactCommon/cxxreact/Instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#ifndef RCT_REMOVE_LEGACY_ARCH
1111

12-
#include "ErrorUtils.h"
12+
#include <jserrorhandler/ErrorUtils.h>
1313
#include "JSBigString.h"
1414
#include "JSBundleType.h"
1515
#include "JSExecutor.h"

packages/react-native/ReactCommon/cxxreact/NativeToJsBridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <jsi/jsi.h>
1616
#include <reactperflogger/BridgeNativeModulePerfLogger.h>
1717

18-
#include "ErrorUtils.h"
18+
#include <jserrorhandler/ErrorUtils.h>
1919
#include "Instance.h"
2020
#include "JSBigString.h"
2121
#include "MessageQueueThread.h"

packages/react-native/ReactCommon/cxxreact/React-cxxreact.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Pod::Spec.new do |s|
4040
s.dependency "React-callinvoker", version
4141
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])
4242
s.dependency "React-perflogger", version
43+
s.dependency "React-jserrorhandler", version
4344
s.dependency "React-jsi", version
4445
s.dependency "React-logger", version
4546
s.dependency "React-debug", version
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "ErrorUtils.h"
9+
10+
namespace facebook::react {
11+
12+
void handleJSError(
13+
jsi::Runtime& runtime,
14+
const jsi::JSError& error,
15+
bool isFatal) {
16+
auto errorUtils = runtime.global().getProperty(runtime, "ErrorUtils");
17+
if (errorUtils.isUndefined() || !errorUtils.isObject() ||
18+
!errorUtils.getObject(runtime).hasProperty(runtime, "reportFatalError") ||
19+
!errorUtils.getObject(runtime).hasProperty(runtime, "reportError")) {
20+
// ErrorUtils was not set up. This probably means the bundle didn't
21+
// load properly.
22+
throw jsi::JSError(
23+
runtime,
24+
"ErrorUtils is not set up properly. Something probably went wrong trying to load the JS bundle. Trying to report error " +
25+
error.getMessage(),
26+
error.getStack());
27+
}
28+
29+
// TODO(janzer): Rewrite this function to return the processed error
30+
// instead of just reporting it through the native module
31+
if (isFatal) {
32+
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(
33+
runtime, "reportFatalError");
34+
func.call(runtime, error.value());
35+
} else {
36+
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(
37+
runtime, "reportError");
38+
func.call(runtime, error.value());
39+
}
40+
}
41+
42+
} // namespace facebook::react
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
12+
namespace facebook::react {
13+
14+
void handleJSError(jsi::Runtime &runtime, const jsi::JSError &error, bool isFatal);
15+
16+
} // namespace facebook::react

packages/react-native/ReactCommon/jserrorhandler/JsErrorHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77

88
#include "JsErrorHandler.h"
9-
#include <cxxreact/ErrorUtils.h>
109
#include <glog/logging.h>
1110
#include <react/bridging/Bridging.h>
1211
#include <react/featureflags/ReactNativeFeatureFlags.h>
1312
#include <ostream>
1413
#include <string>
14+
#include "ErrorUtils.h"
1515
#include "StackTraceParser.h"
1616

1717
using namespace facebook;

0 commit comments

Comments
 (0)