Skip to content

Commit

Permalink
Rename ReactSoftException to ReactSoftExceptionLogger
Browse files Browse the repository at this point in the history
Summary:
ReactSoftException makes it seem like the class is an Exception, when it's actually a logger. This rename I think is more appropriate.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D30251735

fbshipit-source-id: 550bd543388e698774ec31753200bd3f722d8c17
  • Loading branch information
RSNara authored and facebook-github-bot committed Aug 11, 2021
1 parent 56dcc6e commit cbec66e
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableNativeMap;
Expand Down Expand Up @@ -524,7 +524,7 @@ private void toggleElementInspector() {
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("toggleElementInspector", null);
} else {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Cannot toggleElementInspector, CatalystInstance not available"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
Expand Down Expand Up @@ -341,7 +341,7 @@ public void onViewAdded(final View child) {
@Override
public void run() {
if (!child.isShown()) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"A view was illegally added as a child of a ReactRootView. "
Expand Down Expand Up @@ -529,7 +529,7 @@ public void unmountReactApplication() {
removeAllViews();

if (surfaceId == NO_ID) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new RuntimeException(
"unmountReactApplication called on ReactRootView with invalid id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UIManagerListener;
Expand Down Expand Up @@ -365,7 +365,7 @@ private void initializeLifecycleEventListenersForViewTag(final int viewTag) {
if (nodesManager != null) {
nodesManager.initializeEventListenerForUIManagerType(mUIManagerType);
} else {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
NAME,
new RuntimeException(
"initializeLifecycleEventListenersForViewTag could not get NativeAnimatedNodesManager"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UIManager;
Expand Down Expand Up @@ -391,7 +391,7 @@ public void connectAnimatedNodeToView(int animatedNodeTag, int viewTag) {
UIManager uiManager =
UIManagerHelper.getUIManagerForReactTag(mReactApplicationContext, viewTag);
if (uiManager == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"connectAnimatedNodeToView: Animated node could not be connected to UIManager - uiManager disappeared for tag: "
Expand Down Expand Up @@ -753,11 +753,11 @@ private void updateNodes(List<AnimatedNode> nodes) {
if (mEventListenerInitializedForFabric && cyclesDetected == 0) {
// TODO T71377544: investigate these SoftExceptions and see if we can remove entirely
// or fix the root cause
ReactSoftException.logSoftException(TAG, new ReactNoCrashSoftException(ex));
ReactSoftExceptionLogger.logSoftException(TAG, new ReactNoCrashSoftException(ex));
} else if (mEventListenerInitializedForFabric) {
// TODO T71377544: investigate these SoftExceptions and see if we can remove entirely
// or fix the root cause
ReactSoftException.logSoftException(TAG, new ReactNoCrashSoftException(ex));
ReactSoftExceptionLogger.logSoftException(TAG, new ReactNoCrashSoftException(ex));
} else {
throw ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ private void queueRunnable(Runnable runnable) {
// but it's also cheap to leave it here.

if (runnable == null) {
ReactSoftException.logSoftException(TAG, new ReactNoCrashSoftException("runnable is null"));
ReactSoftExceptionLogger.logSoftException(
TAG, new ReactNoCrashSoftException("runnable is null"));
return;
}

final ExecutorService executorService = mExecutorService;
if (executorService == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG, new ReactNoCrashSoftException("executorService is null"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void initializeWithInstance(CatalystInstance catalystInstance) {
throw new IllegalStateException("ReactContext has been already initialized");
}
if (mDestroyed) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException("Cannot initialize ReactContext after it has been destroyed."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected final ReactApplicationContext getReactApplicationContext() {
if (ReactBuildConfig.DEBUG) {
FLog.w(tag, msg);
} else {
ReactSoftException.logSoftException(tag, new RuntimeException(msg));
ReactSoftExceptionLogger.logSoftException(tag, new RuntimeException(msg));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.concurrent.CopyOnWriteArrayList;

@DoNotStrip
public class ReactSoftException {
public class ReactSoftExceptionLogger {
public interface ReactSoftExceptionListener {
void logSoftException(final String category, final Throwable cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@ public class SoftAssertions {
/**
* Throw {@link AssertionException} with a given message. Use this method surrounded with {@code
* if} block with assert condition in case you plan to do string concatenation to produce the
* message. This logs an assertion with ReactSoftException, which decides whether or not to
* message. This logs an assertion with ReactSoftExceptionLogger, which decides whether or not to
* actually throw.
*/
public static void assertUnreachable(String message) {
ReactSoftException.logSoftException("SoftAssertions", new AssertionException(message));
ReactSoftExceptionLogger.logSoftException("SoftAssertions", new AssertionException(message));
}

/**
* Asserts the given condition, throwing an {@link AssertionException} if the condition doesn't
* hold. This logs an assertion with ReactSoftException, which decides whether or not to actually
* throw.
* hold. This logs an assertion with ReactSoftExceptionLogger, which decides whether or not to
* actually throw.
*/
public static void assertCondition(boolean condition, String message) {
if (!condition) {
ReactSoftException.logSoftException("SoftAssertions", new AssertionException(message));
ReactSoftExceptionLogger.logSoftException("SoftAssertions", new AssertionException(message));
}
}

/**
* Asserts that the given Object isn't null, throwing an {@link AssertionException} if it was.
* This logs an assertion with ReactSoftException, which decides whether or not to actually throw.
* This logs an assertion with ReactSoftExceptionLogger, which decides whether or not to actually
* throw.
*/
public static <T> T assertNotNull(@Nullable T instance) {
if (instance == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
"SoftAssertions", new AssertionException("Expected object to not be null!"));
}
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.bridge.ReactMarkerConstants;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UIManager;
Expand Down Expand Up @@ -201,7 +201,7 @@ public FabricUIManager(
@Deprecated
public <T extends View> int addRootView(
final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Do not call addRootView in Fabric; it is unsupported. Call startSurface instead."));
Expand Down Expand Up @@ -336,7 +336,7 @@ private void startSurfaceWithId(SurfaceHandler surfaceHandler, int rootTag, bool

public void stopSurface(final SurfaceHandler surfaceHandler) {
if (!surfaceHandler.isRunning()) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
FabricUIManager.TAG,
new IllegalStateException("Trying to stop surface that hasn't started yet"));
return;
Expand Down Expand Up @@ -384,7 +384,7 @@ public void onCatalystInstanceDestroy() {
FLog.i(TAG, "FabricUIManager.onCatalystInstanceDestroy");

if (mDestroyed) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
FabricUIManager.TAG, new IllegalStateException("Cannot double-destroy FabricUIManager"));
return;
}
Expand Down Expand Up @@ -790,7 +790,7 @@ public void updateRootLayoutSpecs(

// TODO T83615646: make this a hard-crash in the future.
if (surfaceMountingManager == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Cannot updateRootLayoutSpecs on surfaceId that does not exist: " + surfaceId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.ReactIgnorableMountingException;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.RetryableMountingLayerException;
import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
Expand Down Expand Up @@ -131,7 +131,7 @@ public boolean tryDispatchMountItems() {
if (mReDispatchCounter < 10 && didDispatchItems) {
// Executing twice in a row is normal. Only log after that point.
if (mReDispatchCounter > 2) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Re-dispatched "
Expand Down Expand Up @@ -224,14 +224,14 @@ private boolean dispatchMountItems() {
// exception but never crash in debug.
// It's not clear that logging this is even useful, because these events are very
// common, mundane, and there's not much we can do about them currently.
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Caught exception executing ViewCommand: " + command.toString(), e));
}
} catch (Throwable e) {
// Non-Retryable exceptions are logged as soft exceptions in prod, but crash in Debug.
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new RuntimeException(
"Caught exception executing ViewCommand: " + command.toString(), e));
Expand Down Expand Up @@ -280,7 +280,7 @@ private boolean dispatchMountItems() {
}

if (ReactIgnorableMountingException.isIgnorable(e)) {
ReactSoftException.logSoftException(TAG, e);
ReactSoftExceptionLogger.logSoftException(TAG, e);
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.RetryableMountingLayerException;
Expand Down Expand Up @@ -104,7 +104,7 @@ public SurfaceMountingManager startSurface(final int surfaceId) {
// This *will* crash in Debug mode, but not in production.
mSurfaceIdToManager.putIfAbsent(surfaceId, surfaceMountingManager);
if (mSurfaceIdToManager.get(surfaceId) != surfaceMountingManager) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
"Called startSurface more than once for the SurfaceId [" + surfaceId + "]"));
Expand All @@ -121,7 +121,7 @@ public void attachRootView(
getSurfaceManagerEnforced(surfaceId, "attachView");

if (surfaceMountingManager.isStopped()) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG, new IllegalStateException("Trying to attach a view to a stopped surface"));
return;
}
Expand All @@ -148,7 +148,7 @@ public void stopSurface(final int surfaceId) {
mMostRecentSurfaceMountingManager = null;
}
} else {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
"Cannot call stopSurface on non-existent surface: [" + surfaceId + "]"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.RetryableMountingLayerException;
Expand Down Expand Up @@ -174,7 +174,7 @@ public void run() {
}

if (rootView.getId() == mSurfaceId) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalViewOperationException(
"Race condition in addRootView detected. Trying to set an id of ["
Expand Down Expand Up @@ -322,7 +322,7 @@ public void addViewAt(final int parentTag, final int tag, final int index) {
if (viewParent != null) {
int actualParentId =
viewParent instanceof ViewGroup ? ((ViewGroup) viewParent).getId() : View.NO_ID;
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
"addViewAt: cannot insert view ["
Expand Down Expand Up @@ -380,7 +380,7 @@ public void removeViewAt(final int tag, final int parentTag, int index) {

// TODO: throw exception here?
if (parentViewState == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
MountingManager.TAG,
new IllegalStateException(
"Unable to find viewState for tag: [" + parentTag + "] for removeViewAt"));
Expand Down Expand Up @@ -457,7 +457,7 @@ public void removeViewAt(final int tag, final int parentTag, int index) {
// If we can fix the bug there, or remove the need for LayoutAnimation index adjustment
// entirely, we can just throw this exception without regression user experience.
logViewHierarchy(parentView, true);
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
"Tried to remove view ["
Expand Down Expand Up @@ -547,7 +547,7 @@ public void createView(
// This represents a perf issue only, not a correctness issue. In the future we need to
// refactor View preallocation to correct the currently incorrect assumptions.
if (getNullableViewState(reactTag) != null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Cannot CREATE view with tag [" + reactTag + "], already exists."));
Expand Down Expand Up @@ -879,7 +879,7 @@ public void deleteView(int reactTag) {
ViewState viewState = getNullableViewState(reactTag);

if (viewState == null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
MountingManager.TAG,
new IllegalStateException(
"Unable to find viewState for tag: " + reactTag + " for deleteView"));
Expand Down Expand Up @@ -910,7 +910,7 @@ public void preallocateView(
// We treat this as a perf problem and not a logical error. View Preallocation or unexpected
// changes to Differ or C++ Binding could cause some redundant Create instructions.
if (getNullableViewState(reactTag) != null) {
ReactSoftException.logSoftException(
ReactSoftExceptionLogger.logSoftException(
TAG,
new IllegalStateException(
"Cannot Preallocate view with tag [" + reactTag + "], already exists."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package com.facebook.react.fabric.mounting.mountitems;

import androidx.annotation.NonNull;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.bridge.RetryableMountingLayerException;
import com.facebook.react.fabric.mounting.MountingManager;

Expand Down Expand Up @@ -38,7 +38,7 @@ public void execute(@NonNull MountingManager mountingManager) {
// due to race conditions (like the view disappearing after the event is
// queued and before it executes), we log a soft exception and continue along.
// Other categories of errors will still cause a hard crash.
ReactSoftException.logSoftException(TAG, e);
ReactSoftExceptionLogger.logSoftException(TAG, e);
}
}

Expand Down
Loading

0 comments on commit cbec66e

Please sign in to comment.