Skip to content

Convert com.facebook.react.bridge.ReactSoftExceptionLogger to Kotlin #47513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1439,13 +1439,13 @@ public class com/facebook/react/bridge/ReactNoCrashSoftException : java/lang/Run
public fun <init> (Ljava/lang/Throwable;)V
}

public class com/facebook/react/bridge/ReactSoftExceptionLogger {
public fun <init> ()V
public static fun addListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
public static fun clearListeners ()V
public static fun logSoftException (Ljava/lang/String;Ljava/lang/Throwable;)V
public static fun logSoftExceptionVerbose (Ljava/lang/String;Ljava/lang/Throwable;)V
public static fun removeListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
public final class com/facebook/react/bridge/ReactSoftExceptionLogger {
public static final field INSTANCE Lcom/facebook/react/bridge/ReactSoftExceptionLogger;
public static final fun addListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
public static final fun clearListeners ()V
public static final fun logSoftException (Ljava/lang/String;Ljava/lang/Throwable;)V
public static final fun logSoftExceptionVerbose (Ljava/lang/String;Ljava/lang/Throwable;)V
public static final fun removeListener (Lcom/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener;)V
}

public abstract interface class com/facebook/react/bridge/ReactSoftExceptionLogger$ReactSoftExceptionListener {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge

import com.facebook.common.logging.FLog
import com.facebook.proguard.annotations.DoNotStrip
import java.util.concurrent.CopyOnWriteArrayList
import kotlin.jvm.JvmStatic

@DoNotStrip
public object ReactSoftExceptionLogger {

// Use a list instead of a set here because we expect the number of listeners
// to be very small, and we want listeners to be called in a deterministic
// order.
private val listeners: MutableList<ReactSoftExceptionListener> = CopyOnWriteArrayList()

@JvmStatic
public fun addListener(listener: ReactSoftExceptionListener): Unit {
if (!listeners.contains(listener)) {
listeners.add(listener)
}
}

@JvmStatic
public fun removeListener(listener: ReactSoftExceptionListener): Unit {
listeners.remove(listener)
}

@JvmStatic
public fun clearListeners(): Unit {
listeners.clear()
}

@JvmStatic
public fun logSoftExceptionVerbose(category: String, cause: Throwable): Unit {
logSoftException("${category}|${cause.javaClass.simpleName}:${cause.message}", cause)
}

@JvmStatic
public fun logSoftException(category: String, cause: Throwable): Unit {
if (!listeners.isEmpty()) {
for (listener in listeners) {
listener.logSoftException(category, cause)
}
} else {
FLog.e(category, "Unhandled SoftException", cause)
}
}

@JvmStatic
@DoNotStrip
private fun logNoThrowSoftExceptionWithMessage(category: String, message: String) {
logSoftException(category, ReactNoCrashSoftException(message))
}

public fun interface ReactSoftExceptionListener {
public fun logSoftException(category: String, cause: Throwable)
}
}
Loading