From 2ee5a0e41a489f724b0fb837204100e9be7d4e28 Mon Sep 17 00:00:00 2001 From: Thomas Nardone Date: Tue, 17 Dec 2024 06:59:12 -0800 Subject: [PATCH] Categorize SoftAssertions Summary: Extract a constant for SoftAssertions so they can be logged appropriately Changelog: [Internal] Reviewed By: makovkastar Differential Revision: D67296589 --- packages/react-native/ReactAndroid/api/ReactAndroid.api | 1 + .../com/facebook/react/bridge/ReactSoftExceptionLogger.kt | 1 + .../main/java/com/facebook/react/bridge/SoftAssertions.kt | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 9cf38464ce38c8..4adddfaa84a0f5 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1427,6 +1427,7 @@ public final class com/facebook/react/bridge/ReactSoftExceptionLogger$Categories public static final field INSTANCE Lcom/facebook/react/bridge/ReactSoftExceptionLogger$Categories; public static final field RVG_IS_VIEW_CLIPPED Ljava/lang/String; public static final field RVG_ON_VIEW_REMOVED Ljava/lang/String; + public static final field SOFT_ASSERTIONS Ljava/lang/String; } public abstract interface class com/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.kt index 2656b9376eb197..85eb07b93daab0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactSoftExceptionLogger.kt @@ -18,6 +18,7 @@ public object ReactSoftExceptionLogger { public object Categories { public const val RVG_IS_VIEW_CLIPPED: String = "ReactViewGroup.isViewClipped" public const val RVG_ON_VIEW_REMOVED: String = "ReactViewGroup.onViewRemoved" + public const val SOFT_ASSERTIONS: String = "SoftAssertions" } // Use a list instead of a set here because we expect the number of listeners diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.kt index 111006f34d7bae..39f6195365de51 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/SoftAssertions.kt @@ -7,6 +7,8 @@ package com.facebook.react.bridge +import com.facebook.react.bridge.ReactSoftExceptionLogger.Categories.SOFT_ASSERTIONS + /** * Utility class to make assertions that should not hard-crash the app but instead be handled by the * Catalyst app [JSExceptionHandler]. See the javadoc on that class for more information about our @@ -23,7 +25,7 @@ public object SoftAssertions { */ @JvmStatic public fun assertUnreachable(message: String): Unit { - ReactSoftExceptionLogger.logSoftException("SoftAssertions", AssertionException(message)) + ReactSoftExceptionLogger.logSoftException(SOFT_ASSERTIONS, AssertionException(message)) } /** @@ -34,7 +36,7 @@ public object SoftAssertions { @JvmStatic public fun assertCondition(condition: Boolean, message: String): Unit { if (!condition) { - ReactSoftExceptionLogger.logSoftException("SoftAssertions", AssertionException(message)) + ReactSoftExceptionLogger.logSoftException(SOFT_ASSERTIONS, AssertionException(message)) } } @@ -46,7 +48,7 @@ public object SoftAssertions { public fun assertNotNull(instance: T?): T? { if (instance == null) { ReactSoftExceptionLogger.logSoftException( - "SoftAssertions", AssertionException("Expected object to not be null!")) + SOFT_ASSERTIONS, AssertionException("Expected object to not be null!")) } return instance }