Skip to content

Commit

Permalink
Refactor: Delete ExceptionLogger interface in DevSupportManagerBase
Browse files Browse the repository at this point in the history
Summary:
## Rationale
- ExceptionLogger [is a private interface](https://www.internalfb.com/code/fbsource/[0fa3b362177087a2b5c4544c9d65a01f7f09b0e7]/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java?lines=256-258) is [only implemented by JSExceptionLogger](https://www.internalfb.com/code/search?q=repo%3Afbsource%20regex%3Aon%20implements%20ExceptionLogger&tab=all)
- You can only have one ExceptionLogger, which is [a JSExceptionLogger created in DevLoadingViewBase](https://www.internalfb.com/code/fbsource/[0fa3b362177087a2b5c4544c9d65a01f7f09b0e7]/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java?lines=227).

So, we could remove this generalized ExceptionLogger interface and just use replace it with an instance method on DevSupportManagerBase. This makes DevSupportManagerBase easier to reason about.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D29007764

fbshipit-source-id: 357f0e2e07f381f43b4b5e0c5f1415f87af7fd88
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 10, 2021
1 parent 1d14df2 commit 61dda32
Showing 1 changed file with 18 additions and 35 deletions.
Expand Up @@ -83,8 +83,6 @@ public interface CallbackWithBundleLoader {
public static final String EMOJI_HUNDRED_POINTS_SYMBOL = " \uD83D\uDCAF";
public static final String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " \uD83D\uDE45";

private final List<ExceptionLogger> mExceptionLoggers = new ArrayList<>();

private final Context mApplicationContext;
private final ShakeDetector mShakeDetector;
private final BroadcastReceiver mReloadAppBroadcastReceiver;
Expand Down Expand Up @@ -204,8 +202,6 @@ public void onReceive(Context context, Intent intent) {
mRedBoxHandler = redBoxHandler;
mDevLoadingViewController = new DevLoadingViewController(reactInstanceDevHelper);

mExceptionLoggers.add(new JSExceptionLogger());

if (mDevSettings.isStartSamplingProfilerOnInit()) {
// Only start the profiler. If its already running, there is an error
if (!mIsSamplingProfilerEnabled) {
Expand All @@ -223,44 +219,31 @@ public void onReceive(Context context, Intent intent) {
@Override
public void handleException(Exception e) {
if (mIsDevSupportEnabled) {

for (ExceptionLogger logger : mExceptionLoggers) {
logger.log(e);
}

logJSException(e);
} else {
mDefaultNativeModuleCallExceptionHandler.handleException(e);
}
}

private interface ExceptionLogger {
void log(Exception ex);
}

private class JSExceptionLogger implements ExceptionLogger {

@Override
public void log(Exception e) {
StringBuilder message =
new StringBuilder(
e.getMessage() == null ? "Exception in native call from JS" : e.getMessage());
Throwable cause = e.getCause();
while (cause != null) {
message.append("\n\n").append(cause.getMessage());
cause = cause.getCause();
}
private void logJSException(Exception e) {
StringBuilder message =
new StringBuilder(
e.getMessage() == null ? "Exception in native call from JS" : e.getMessage());
Throwable cause = e.getCause();
while (cause != null) {
message.append("\n\n").append(cause.getMessage());
cause = cause.getCause();
}

if (e instanceof JSException) {
FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
String stack = ((JSException) e).getStack();
message.append("\n\n").append(stack);
if (e instanceof JSException) {
FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
String stack = ((JSException) e).getStack();
message.append("\n\n").append(stack);

// TODO #11638796: convert the stack into something useful
showNewError(
message.toString(), new StackFrame[] {}, JSEXCEPTION_ERROR_COOKIE, ErrorType.JS);
} else {
showNewJavaError(message.toString(), e);
}
// TODO #11638796: convert the stack into something useful
showNewError(message.toString(), new StackFrame[] {}, JSEXCEPTION_ERROR_COOKIE, ErrorType.JS);
} else {
showNewJavaError(message.toString(), e);
}
}

Expand Down

0 comments on commit 61dda32

Please sign in to comment.