Skip to content

Commit 8967bc5

Browse files
javachefacebook-github-bot
authored andcommitted
Move ErrorUtils from cxxreact to jserrorhandler
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] Differential Revision: D108786498
1 parent fc7dc74 commit 8967bc5

11 files changed

Lines changed: 68 additions & 40 deletions

File tree

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;

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 "ReactCommon/turbomodule/bridging"
4241
add_dependency(s, "React-featureflags")
4342
add_dependency(s, "React-debug")

packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp

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

88
#include "jsireact/JSIExecutor.h"
99

10-
#include <cxxreact/ErrorUtils.h>
1110
#include <cxxreact/JSBigString.h>
1211
#include <cxxreact/ModuleRegistry.h>
1312
#include <cxxreact/ReactMarker.h>
1413
#include <cxxreact/TraceSection.h>
1514
#include <folly/json.h>
1615
#include <glog/logging.h>
16+
#include <jserrorhandler/ErrorUtils.h>
1717
#include <jsi/JSIDynamic.h>
1818
#include <jsi/instrumentation.h>
1919
#include <reactperflogger/BridgeNativeModulePerfLogger.h>

packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "RuntimeScheduler_Legacy.h"
1212
#endif
1313

14-
#include <cxxreact/ErrorUtils.h>
1514
#include <cxxreact/TraceSection.h>
15+
#include <jserrorhandler/ErrorUtils.h>
1616
#ifndef RCT_REMOVE_LEGACY_ARCH
1717
#include <react/featureflags/ReactNativeFeatureFlags.h>
1818
#endif

0 commit comments

Comments
 (0)