Skip to content

Commit 07816cb

Browse files
javachemeta-codesync[bot]
authored andcommitted
Move ErrorUtils from cxxreact to jserrorhandler (#57236)
Summary: Pull Request resolved: #57236 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 fbshipit-source-id: 6a34ec47665558ac9c91343253e027ed1df70e93
1 parent 1172a8a commit 07816cb

25 files changed

Lines changed: 88 additions & 47 deletions

packages/react-native/Package.swift

Lines changed: 5 additions & 5 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
@@ -212,7 +212,7 @@ let reactJsiTooling = RNTarget(
212212
let reactJsiExecutor = RNTarget(
213213
name: .reactJsiExecutor,
214214
path: "ReactCommon/jsiexecutor",
215-
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactJsiTooling]
215+
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactJsErrorHandler, .reactJsiTooling]
216216
)
217217

218218
/// React-hermes.podspec
@@ -259,7 +259,7 @@ let reactRuntimeScheduler = RNTarget(
259259
name: .reactRuntimeScheduler,
260260
path: "ReactCommon/react/renderer/runtimescheduler",
261261
excludedPaths: ["tests"],
262-
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .reactCxxReact, .reactPerfLogger, .reactPerformanceTimeline, .reactRendererConsistency, .reactUtils, .reactRuntimeExecutor]
262+
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .reactCxxReact, .reactJsErrorHandler, .reactPerfLogger, .reactPerformanceTimeline, .reactRendererConsistency, .reactUtils, .reactRuntimeExecutor]
263263
)
264264

265265
/// React-bridging.podspec
@@ -276,7 +276,7 @@ let reactJsErrorHandler = RNTarget(
276276
name: .reactJsErrorHandler,
277277
path: "ReactCommon/jserrorhandler",
278278
excludedPaths: ["tests"],
279-
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
279+
dependencies: [.reactNativeDependencies, .jsi, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
280280
)
281281

282282
/// React-graphicsApple
@@ -307,7 +307,7 @@ let reactTurboModuleCore = RNTarget(
307307
"ReactCommon/react/nativemodule/core/platform/ios",
308308
],
309309
excludedPaths: ["platform/android", "iostests"],
310-
dependencies: [.reactNativeDependencies, .reactDebug, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
310+
dependencies: [.reactNativeDependencies, .reactDebug, .reactJsErrorHandler, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
311311
)
312312

313313
/// React-defaultsnativemodule.podspec

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Pod::Spec.new do |s|
2929
s.source = source
3030
s.source_files = podspec_sources("*.{cpp,h}", "*.h")
3131
s.pod_target_xcconfig = {
32-
"HEADER_SEARCH_PATHS" => "\"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimeexecutor/React_runtimeexecutor.framework/Headers\"",
32+
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/..\" \"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimeexecutor/React_runtimeexecutor.framework/Headers\"",
3333
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard()
3434
}
3535
s.header_dir = "cxxreact"
@@ -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;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Pod::Spec.new do |s|
2828
s.platforms = min_supported_versions
2929
s.source = source
3030
s.header_dir = "jserrorhandler"
31-
s.source_files = podspec_sources(["JsErrorHandler.{cpp,h}", "StackTraceParser.{cpp,h}"], ["JsErrorHandler.h", "StackTraceParser.h"])
31+
s.source_files = podspec_sources(["ErrorUtils.{cpp,h}", "JsErrorHandler.{cpp,h}", "StackTraceParser.{cpp,h}"], ["ErrorUtils.h", "JsErrorHandler.h", "StackTraceParser.h"])
3232
s.pod_target_xcconfig = {
3333
"USE_HEADERMAP" => "YES",
3434
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard()
@@ -37,7 +37,6 @@ Pod::Spec.new do |s|
3737
resolve_use_frameworks(s, header_mappings_dir: '../', module_name: "React_jserrorhandler")
3838

3939
s.dependency "React-jsi"
40-
s.dependency "React-cxxreact"
4140
s.dependency "React-bridging"
4241
add_dependency(s, "React-featureflags")
4342
add_dependency(s, "React-debug")

0 commit comments

Comments
 (0)