Skip to content

Commit

Permalink
Emit logs in "module not found" scenarios
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Apr 21, 2023
1 parent af5c2d2 commit 555014a
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 555014a

Please sign in to comment.