Skip to content

Commit

Permalink
Record latest error type in dev support
Browse files Browse the repository at this point in the history
Summary:
In DevSupportManagerBase.java->updateLastErrorInfo(), errorType was not recorded like errorMessage and errorStack, we could either remove errorType as a parameter or recorded it for future use. This diff recorded it since it would make the error info complete.

Changelog:
[Android][Changed] - Record latest error type in dev support

Reviewed By: PeteTheHeat

Differential Revision: D26884647

fbshipit-source-id: 712d82667bdc4b3410f4c83a3df9a456af6d9061
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Mar 12, 2021
1 parent ba61267 commit 423453e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.ErrorCustomizer;
import com.facebook.react.devsupport.interfaces.ErrorType;
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
import com.facebook.react.devsupport.interfaces.StackFrame;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
Expand Down Expand Up @@ -85,12 +86,6 @@ public interface CallbackWithBundleLoader {
"flipper://null/Hermesdebuggerrn?device=React%20Native";
private static final String FLIPPER_DEVTOOLS_URL = "flipper://null/React?device=React%20Native";
private boolean mIsSamplingProfilerEnabled = false;

private enum ErrorType {
JS,
NATIVE
}

private static final String EXOPACKAGE_LOCATION_FORMAT =
"/data/local/tmp/exopackage/%s//secondary-dex";

Expand Down Expand Up @@ -124,6 +119,7 @@ private enum ErrorType {
private @Nullable RedBoxHandler mRedBoxHandler;
private @Nullable String mLastErrorTitle;
private @Nullable StackFrame[] mLastErrorStack;
private @Nullable ErrorType mLastErrorType;
private int mLastErrorCookie = 0;
private @Nullable DevBundleDownloadListener mBundleDownloadListener;
private @Nullable List<ErrorCustomizer> mErrorCustomizers;
Expand Down Expand Up @@ -353,7 +349,7 @@ public void run() {
updateLastErrorInfo(message, stack, errorCookie, ErrorType.JS);
// JS errors are reported here after source mapping.
if (mRedBoxHandler != null) {
mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.JS);
mRedBoxHandler.handleRedbox(message, stack, ErrorType.JS);
mRedBoxDialog.resetReporting();
}
mRedBoxDialog.show();
Expand Down Expand Up @@ -420,7 +416,7 @@ public void run() {
// Only report native errors here. JS errors are reported
// inside {@link #updateJSError} after source mapping.
if (mRedBoxHandler != null && errorType == ErrorType.NATIVE) {
mRedBoxHandler.handleRedbox(message, stack, RedBoxHandler.ErrorType.NATIVE);
mRedBoxHandler.handleRedbox(message, stack, ErrorType.NATIVE);
}
mRedBoxDialog.resetReporting();
mRedBoxDialog.show();
Expand Down Expand Up @@ -1002,6 +998,11 @@ public void run() {
return mLastErrorStack;
}

@Override
public @Nullable ErrorType getLastErrorType() {
return mLastErrorType;
}

@Override
public void onPackagerConnected() {
// No-op
Expand Down Expand Up @@ -1083,6 +1084,7 @@ private void updateLastErrorInfo(
mLastErrorTitle = message;
mLastErrorStack = stack;
mLastErrorCookie = errorCookie;
mLastErrorType = errorType;
}

private void reloadJSInProxyMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.facebook.react.devsupport.interfaces.DevSplitBundleCallback;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.ErrorCustomizer;
import com.facebook.react.devsupport.interfaces.ErrorType;
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
import com.facebook.react.devsupport.interfaces.StackFrame;
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
Expand Down Expand Up @@ -154,6 +155,11 @@ public void isPackagerRunning(final PackagerStatusCallback callback) {
return null;
}

@Override
public @Nullable ErrorType getLastErrorType() {
return null;
}

@Override
public void registerErrorCustomizer(ErrorCustomizer errorCustomizer) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.text.SpannedString;
import androidx.annotation.Nullable;
import com.facebook.react.devsupport.interfaces.ErrorType;
import com.facebook.react.devsupport.interfaces.StackFrame;

/**
Expand All @@ -18,21 +19,6 @@
* setRedBoxHandler in ReactInstanceManager.
*/
public interface RedBoxHandler {
enum ErrorType {
JS("JS"),
NATIVE("Native");

private final String name;

ErrorType(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

/** Callback interface for {@link #reportRedbox}. */
interface ReportCompletedListener {
void onReportSuccess(SpannedString spannedString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public interface DevSupportManager extends NativeModuleCallExceptionHandler {
@Nullable
StackFrame[] getLastErrorStack();

@Nullable
ErrorType getLastErrorType();

void registerErrorCustomizer(ErrorCustomizer errorCustomizer);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its 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.devsupport.interfaces;

public enum ErrorType {
JS("JS"),
NATIVE("Native");

private final String name;

ErrorType(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

0 comments on commit 423453e

Please sign in to comment.