Move ErrorUtils from cxxreact to jserrorhandler (#57236)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/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
This commit is contained in:
Pieter De Baets authored and meta-codesync[bot] committed 2026-07-06 07:43:37 -07:00
1 parent 1172a8a5f6
commit 07816cba56
25 files changed
+88 -47

No files matched your search

+5 -5
View File
@@ -198,7 +198,7 @@ let reactCxxReact = RNTarget(
path: "ReactCommon/cxxreact",
searchPaths: [CallInvokerPath],
excludedPaths: ["tests"],
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .logger, .reactDebug, .reactJsInspector]
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .logger, .reactDebug, .reactJsErrorHandler, .reactJsInspector]
)
/// React-jsitooling.podspec
@@ -212,7 +212,7 @@ let reactJsiTooling = RNTarget(
let reactJsiExecutor = RNTarget(
name: .reactJsiExecutor,
path: "ReactCommon/jsiexecutor",
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactJsiTooling]
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactJsErrorHandler, .reactJsiTooling]
)
/// React-hermes.podspec
@@ -259,7 +259,7 @@ let reactRuntimeScheduler = RNTarget(
name: .reactRuntimeScheduler,
path: "ReactCommon/react/renderer/runtimescheduler",
excludedPaths: ["tests"],
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .reactCxxReact, .reactPerfLogger, .reactPerformanceTimeline, .reactRendererConsistency, .reactUtils, .reactRuntimeExecutor]
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .reactCxxReact, .reactJsErrorHandler, .reactPerfLogger, .reactPerformanceTimeline, .reactRendererConsistency, .reactUtils, .reactRuntimeExecutor]
)
/// React-bridging.podspec
@@ -276,7 +276,7 @@ let reactJsErrorHandler = RNTarget(
name: .reactJsErrorHandler,
path: "ReactCommon/jserrorhandler",
excludedPaths: ["tests"],
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
dependencies: [.reactNativeDependencies, .jsi, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
)
/// React-graphicsApple
@@ -307,7 +307,7 @@ let reactTurboModuleCore = RNTarget(
"ReactCommon/react/nativemodule/core/platform/ios",
],
excludedPaths: ["platform/android", "iostests"],
dependencies: [.reactNativeDependencies, .reactDebug, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
dependencies: [.reactNativeDependencies, .reactDebug, .reactJsErrorHandler, .reactFeatureFlags, .reactUtils, .reactPerfLogger, .reactCxxReact, .reactTurboModuleBridging, .yoga, .reactRuntimeExecutor]
)
/// React-defaultsnativemodule.podspec
@@ -18,6 +18,7 @@ target_link_libraries(react_cxxreact
callinvoker
folly_runtime
glog
jserrorhandler
jsi
jsinspector
logger
@@ -7,36 +7,6 @@
#pragma once
#include <jsi/jsi.h>
#warning Deprecated: use <jserrorhandler/ErrorUtils.h> instead.
namespace facebook::react {
inline static void handleJSError(jsi::Runtime &runtime, const jsi::JSError &error, bool isFatal)
{
auto errorUtils = runtime.global().getProperty(runtime, "ErrorUtils");
if (errorUtils.isUndefined() || !errorUtils.isObject() ||
!errorUtils.getObject(runtime).hasProperty(runtime, "reportFatalError") ||
!errorUtils.getObject(runtime).hasProperty(runtime, "reportError")) {
// ErrorUtils was not set up. This probably means the bundle didn't
// load properly.
throw jsi::JSError(
runtime,
"ErrorUtils is not set up properly. Something probably went wrong trying to load the JS bundle. Trying to report error " +
error.getMessage(),
error.getStack());
}
// TODO(janzer): Rewrite this function to return the processed error
// instead of just reporting it through the native module
if (isFatal) {
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(runtime, "reportFatalError");
func.call(runtime, error.value());
} else {
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(runtime, "reportError");
func.call(runtime, error.value());
}
}
} // namespace facebook::react
#include <jserrorhandler/ErrorUtils.h>
@@ -9,7 +9,7 @@
#ifndef RCT_REMOVE_LEGACY_ARCH
#include "ErrorUtils.h"
#include <jserrorhandler/ErrorUtils.h>
#include "JSBigString.h"
#include "JSBundleType.h"
#include "JSExecutor.h"
@@ -15,7 +15,7 @@
#include <jsi/jsi.h>
#include <reactperflogger/BridgeNativeModulePerfLogger.h>
#include "ErrorUtils.h"
#include <jserrorhandler/ErrorUtils.h>
#include "Instance.h"
#include "JSBigString.h"
#include "MessageQueueThread.h"
@@ -29,7 +29,7 @@ Pod::Spec.new do |s|
s.source = source
s.source_files = podspec_sources("*.{cpp,h}", "*.h")
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_CONFIGURATION_BUILD_DIR)/React-debug/React_debug.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimeexecutor/React_runtimeexecutor.framework/Headers\"",
"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\"",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard()
}
s.header_dir = "cxxreact"
@@ -40,6 +40,7 @@ Pod::Spec.new do |s|
s.dependency "React-callinvoker", version
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])
s.dependency "React-perflogger", version
s.dependency "React-jserrorhandler", version
s.dependency "React-jsi", version
s.dependency "React-logger", version
s.dependency "React-debug", version
@@ -0,0 +1,42 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ErrorUtils.h"
namespace facebook::react {
void handleJSError(
jsi::Runtime& runtime,
const jsi::JSError& error,
bool isFatal) {
auto errorUtils = runtime.global().getProperty(runtime, "ErrorUtils");
if (errorUtils.isUndefined() || !errorUtils.isObject() ||
!errorUtils.getObject(runtime).hasProperty(runtime, "reportFatalError") ||
!errorUtils.getObject(runtime).hasProperty(runtime, "reportError")) {
// ErrorUtils was not set up. This probably means the bundle didn't
// load properly.
throw jsi::JSError(
runtime,
"ErrorUtils is not set up properly. Something probably went wrong trying to load the JS bundle. Trying to report error " +
error.getMessage(),
error.getStack());
}
// TODO(janzer): Rewrite this function to return the processed error
// instead of just reporting it through the native module
if (isFatal) {
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(
runtime, "reportFatalError");
func.call(runtime, error.value());
} else {
auto func = errorUtils.asObject(runtime).getPropertyAsFunction(
runtime, "reportError");
func.call(runtime, error.value());
}
}
} // namespace facebook::react
@@ -0,0 +1,16 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <jsi/jsi.h>
namespace facebook::react {
void handleJSError(jsi::Runtime &runtime, const jsi::JSError &error, bool isFatal);
} // namespace facebook::react
@@ -6,12 +6,12 @@
*/
#include "JsErrorHandler.h"
#include <cxxreact/ErrorUtils.h>
#include <glog/logging.h>
#include <react/bridging/Bridging.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <ostream>
#include <string>
#include "ErrorUtils.h"
#include "StackTraceParser.h"
using namespace facebook;
@@ -28,7 +28,7 @@ Pod::Spec.new do |s|
s.platforms = min_supported_versions
s.source = source
s.header_dir = "jserrorhandler"
s.source_files = podspec_sources(["JsErrorHandler.{cpp,h}", "StackTraceParser.{cpp,h}"], ["JsErrorHandler.h", "StackTraceParser.h"])
s.source_files = podspec_sources(["ErrorUtils.{cpp,h}", "JsErrorHandler.{cpp,h}", "StackTraceParser.{cpp,h}"], ["ErrorUtils.h", "JsErrorHandler.h", "StackTraceParser.h"])
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard()
@@ -37,7 +37,6 @@ Pod::Spec.new do |s|
resolve_use_frameworks(s, header_mappings_dir: '../', module_name: "React_jserrorhandler")
s.dependency "React-jsi"
s.dependency "React-cxxreact"
s.dependency "React-bridging"
add_dependency(s, "React-featureflags")
add_dependency(s, "React-debug")
@@ -26,7 +26,8 @@ Pod::Spec.new do |s|
s.platforms = min_supported_versions
s.source = source
s.source_files = podspec_sources("jsireact/*.{cpp,h}", "jsireact/*.h")
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard() }
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/..\"" }
s.header_dir = "jsireact"
s.dependency "React-cxxreact"
@@ -7,13 +7,13 @@
#include "jsireact/JSIExecutor.h"
#include <cxxreact/ErrorUtils.h>
#include <cxxreact/JSBigString.h>
#include <cxxreact/ModuleRegistry.h>
#include <cxxreact/ReactMarker.h>
#include <cxxreact/TraceSection.h>
#include <folly/json.h>
#include <glog/logging.h>
#include <jserrorhandler/ErrorUtils.h>
#include <jsi/JSIDynamic.h>
#include <jsi/instrumentation.h>
#include <reactperflogger/BridgeNativeModulePerfLogger.h>
@@ -15,6 +15,7 @@ target_include_directories(react_renderer_runtimescheduler PUBLIC ${REACT_COMMON
target_link_libraries(react_renderer_runtimescheduler
callinvoker
jserrorhandler
jsi
react_debug
react_performance_timeline
@@ -48,6 +48,7 @@ Pod::Spec.new do |s|
s.dependency "React-featureflags"
s.dependency "React-timing"
s.dependency "React-jsi"
s.dependency "React-jserrorhandler"
s.dependency "React-performancetimeline"
s.dependency "React-rendererconsistency"
add_dependency(s, "React-debug")
@@ -11,8 +11,8 @@
#include "RuntimeScheduler_Legacy.h"
#endif
#include <cxxreact/ErrorUtils.h>
#include <cxxreact/TraceSection.h>
#include <jserrorhandler/ErrorUtils.h>
#ifndef RCT_REMOVE_LEGACY_ARCH
#include <react/featureflags/ReactNativeFeatureFlags.h>
#endif
@@ -8,12 +8,12 @@
#include "ReactInstance.h"
#include <ReactCommon/RuntimeExecutor.h>
#include <cxxreact/ErrorUtils.h>
#include <cxxreact/JSBigString.h>
#include <cxxreact/JSExecutor.h>
#include <cxxreact/ReactMarker.h>
#include <cxxreact/TraceSection.h>
#include <glog/logging.h>
#include <jserrorhandler/ErrorUtils.h>
#include <jsi/JSIDynamic.h>
#include <jsi/hermes-interfaces.h>
#include <jsi/instrumentation.h>
@@ -1140,6 +1140,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);
@@ -1136,6 +1136,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);
@@ -1140,6 +1140,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);
@@ -3973,6 +3973,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::installLegacyUIManagerConstantsProviderBinding(facebook::jsi::Runtime& runtime);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
@@ -3958,6 +3958,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::installLegacyUIManagerConstantsProviderBinding(facebook::jsi::Runtime& runtime);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
@@ -3973,6 +3973,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::installLegacyUIManagerConstantsProviderBinding(facebook::jsi::Runtime& runtime);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
@@ -700,6 +700,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);
@@ -697,6 +697,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);
@@ -700,6 +700,7 @@ void facebook::react::fromRawValue(const facebook::react::PropsParserContext&, c
void facebook::react::fromRawValueShared(const facebook::react::ContextContainer& contextContainer, int32_t surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result, facebook::react::parsePlatformColorFn parsePlatformColor);
void facebook::react::fromString(const std::string& string, facebook::react::AccessibilityTraits& result);
void facebook::react::g_setNativeAnimatedNowTimestampFunction(facebook::react::TimePointFunction nowFunction);
void facebook::react::handleJSError(facebook::jsi::Runtime& runtime, const facebook::jsi::JSError& error, bool isFatal);
void facebook::react::parseProcessedBackgroundImage(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BackgroundImage>& result);
void facebook::react::parseProcessedBoxShadow(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::BoxShadow>& result);
void facebook::react::parseProcessedFilter(const facebook::react::PropsParserContext& context, const facebook::react::RawValue& value, std::vector<facebook::react::FilterFunction>& result);