From 555014a634d466b220de812212726466f89d475e Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 21 Apr 2023 16:37:04 -0700 Subject: [PATCH] Emit logs in "module not found" scenarios Summary: In the TurboModule interop layer, several modules are appearing as null. It's unclear why. We landed a few module resolution simplification diffs, to *attempt* to mitigate the problem: D45131297. But we're not sure if those diffs will be 100% successful. So, this diff inserts two logs into the TurboModule system, for scenarios we know could lead to TurboModules being null. The hope: this helps us understand the actual problem, in case our earlier fix attempt (i.e: D45131297) fails. Notes: - These logs are temporary. - These logs will only run in the TurboModule interop's test group. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D45197703 fbshipit-source-id: 4401a6111492444cc4b405c52183d02df94c3828 --- .../turbomodule/core/TurboModuleManager.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java index 4cc3ac4f5dd676..c17a99bfef88db 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java @@ -10,12 +10,15 @@ import androidx.annotation.GuardedBy; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.CxxModuleWrapper; import com.facebook.react.bridge.JSIModule; import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactNoCrashSoftException; +import com.facebook.react.bridge.ReactSoftExceptionLogger; import com.facebook.react.bridge.RuntimeExecutor; import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; @@ -227,6 +230,14 @@ public NativeModule getModule(String moduleName) { /* * Always return null after cleanup has started, so that getNativeModule(moduleName) returns null. */ + logError( + "getModule(): Tried to get module \"" + + moduleName + + "\", but TurboModuleManager was tearing down. Returning null. Was legacy: " + + isLegacyModule(moduleName) + + ". Was turbo: " + + isTurboModule(moduleName) + + "."); return null; } @@ -302,6 +313,15 @@ private NativeModule getOrCreateModule( * Therefore, we should initialize on the TurboModule now. */ nativeModule.initialize(); + } else { + logError( + "getOrCreateModule(): Unable to create module \"" + + moduleName + + "\". Was legacy: " + + isLegacyModule(moduleName) + + ". Was turbo: " + + isTurboModule(moduleName) + + "."); } TurboModulePerfLogger.moduleCreateSetUpEnd(moduleName, moduleHolder.getModuleId()); @@ -374,6 +394,14 @@ public boolean hasModule(String moduleName) { return false; } + public static void logError(String message) { + FLog.e("TurboModuleManager", message); + if (shouldRouteTurboModulesThroughInteropLayer()) { + ReactSoftExceptionLogger.logSoftException( + "TurboModuleManager", new ReactNoCrashSoftException(message)); + } + } + private native HybridData initHybrid( RuntimeExecutor runtimeExecutor, CallInvokerHolderImpl jsCallInvokerHolder,