Make ReactModuleSpecProcessor print stacktrace when typeElement.getAnnotation fails

Summary:
WHen porting TurboModules or adding new TurboModules, ReactModuleSpecProcessor may fail during buck build, and when the failure is caused by typeElement.getAnnotation, no useful information gets collected, making it difficult to debug.
So here I am adding a try & catch so we can get useful debugging info.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D35767207

fbshipit-source-id: 7e1f9dfbfd31339ab37af19c51d85085e100955a
This commit is contained in:
Alex Liang
2022-04-22 16:57:51 -07:00
committed by Facebook GitHub Bot
parent ffaa5d69bc
commit 7454044542
2 changed files with 13 additions and 1 deletions
@@ -22,6 +22,8 @@ rn_java_library(
source = "8",
target = "8",
deps = [
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_target("java/com/facebook/react/common:common"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/javapoet:javapoet"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
@@ -10,7 +10,9 @@ package com.facebook.react.module.processing;
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.tools.Diagnostic.Kind.ERROR;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.SuppressFieldNotInitialized;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfo;
@@ -87,7 +89,15 @@ public class ReactModuleSpecProcessor extends AbstractProcessor {
}
TypeElement typeElement = (TypeElement) reactModuleListElement;
ReactModuleList reactModuleList = typeElement.getAnnotation(ReactModuleList.class);
ReactModuleList reactModuleList = null;
try {
reactModuleList = typeElement.getAnnotation(ReactModuleList.class);
} catch (Exception ex) {
FLog.i(
ReactConstants.TAG, "Could not reactModuleList from typeElement.getAnnotation()", ex);
throw ex;
}
if (reactModuleList == null) {
continue;