Skip to content

Commit 555014a

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent af5c2d2 commit 555014a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
import androidx.annotation.GuardedBy;
1111
import androidx.annotation.NonNull;
1212
import androidx.annotation.Nullable;
13+
import com.facebook.common.logging.FLog;
1314
import com.facebook.infer.annotation.Assertions;
1415
import com.facebook.jni.HybridData;
1516
import com.facebook.proguard.annotations.DoNotStrip;
1617
import com.facebook.react.bridge.CxxModuleWrapper;
1718
import com.facebook.react.bridge.JSIModule;
1819
import com.facebook.react.bridge.NativeModule;
20+
import com.facebook.react.bridge.ReactNoCrashSoftException;
21+
import com.facebook.react.bridge.ReactSoftExceptionLogger;
1922
import com.facebook.react.bridge.RuntimeExecutor;
2023
import com.facebook.react.config.ReactFeatureFlags;
2124
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
@@ -227,6 +230,14 @@ public NativeModule getModule(String moduleName) {
227230
/*
228231
* Always return null after cleanup has started, so that getNativeModule(moduleName) returns null.
229232
*/
233+
logError(
234+
"getModule(): Tried to get module \""
235+
+ moduleName
236+
+ "\", but TurboModuleManager was tearing down. Returning null. Was legacy: "
237+
+ isLegacyModule(moduleName)
238+
+ ". Was turbo: "
239+
+ isTurboModule(moduleName)
240+
+ ".");
230241
return null;
231242
}
232243

@@ -302,6 +313,15 @@ private NativeModule getOrCreateModule(
302313
* Therefore, we should initialize on the TurboModule now.
303314
*/
304315
nativeModule.initialize();
316+
} else {
317+
logError(
318+
"getOrCreateModule(): Unable to create module \""
319+
+ moduleName
320+
+ "\". Was legacy: "
321+
+ isLegacyModule(moduleName)
322+
+ ". Was turbo: "
323+
+ isTurboModule(moduleName)
324+
+ ".");
305325
}
306326

307327
TurboModulePerfLogger.moduleCreateSetUpEnd(moduleName, moduleHolder.getModuleId());
@@ -374,6 +394,14 @@ public boolean hasModule(String moduleName) {
374394
return false;
375395
}
376396

397+
public static void logError(String message) {
398+
FLog.e("TurboModuleManager", message);
399+
if (shouldRouteTurboModulesThroughInteropLayer()) {
400+
ReactSoftExceptionLogger.logSoftException(
401+
"TurboModuleManager", new ReactNoCrashSoftException(message));
402+
}
403+
}
404+
377405
private native HybridData initHybrid(
378406
RuntimeExecutor runtimeExecutor,
379407
CallInvokerHolderImpl jsCallInvokerHolder,

0 commit comments

Comments
 (0)