From 7454044542252be56c18cd98dc0536f7046d1c6d Mon Sep 17 00:00:00 2001 From: Alex Liang Date: Fri, 22 Apr 2022 16:57:51 -0700 Subject: [PATCH] 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 --- .../java/com/facebook/react/module/processing/BUCK | 2 ++ .../module/processing/ReactModuleSpecProcessor.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK b/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK index e578bc87e9e..6b2ab0bed76 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/module/processing/BUCK @@ -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"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java b/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java index 729c609c3cd..9ea0b1d7fe9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java +++ b/ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java @@ -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;