mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor: Delete ExceptionLogger interface in DevSupportManagerBase
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1d14df217e
commit
61dda3242d
+18
-35
@@ -83,8 +83,6 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
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;
|
||||
@@ -204,8 +202,6 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
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) {
|
||||
@@ -223,44 +219,31 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
|
||||
@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 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();
|
||||
}
|
||||
|
||||
private class JSExceptionLogger implements ExceptionLogger {
|
||||
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);
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user