Display JS exceptions and stacks in a red box

Reviewed By: frantic

Differential Revision: D3428952

fbshipit-source-id: e2b77487d54a3d89039661943061a0137f8410c0
This commit is contained in:
Marc Horowitz
2016-06-30 19:01:25 -07:00
committed by Facebook Github Bot 6
parent 730619dabf
commit ff31128200
3 changed files with 73 additions and 3 deletions

View File

@@ -79,6 +79,7 @@ import com.facebook.react.modules.debug.DeveloperSettings;
public class DevSupportManagerImpl implements DevSupportManager {
private static final int JAVA_ERROR_COOKIE = -1;
private static final int JSEXCEPTION_ERROR_COOKIE = -1;
private static final String JS_BUNDLE_FILE_NAME = "ReactNativeDevBundle.js";
private static enum ErrorType {
JS,
@@ -194,7 +195,13 @@ public class DevSupportManagerImpl implements DevSupportManager {
public void handleException(Exception e) {
if (mIsDevSupportEnabled) {
FLog.e(ReactConstants.TAG, "Exception in native call from JS", e);
showNewJavaError(e.getMessage(), e);
if (e instanceof JSException) {
// TODO #11638796: convert the stack into something useful
showNewError(e.getMessage() + "\n\n" + ((JSException) e).getStack(), new StackFrame[] {},
JSEXCEPTION_ERROR_COOKIE, ErrorType.JS);
} else {
showNewJavaError(e.getMessage(), e);
}
} else {
mDefaultNativeModuleCallExceptionHandler.handleException(e);
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.devsupport;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* This represents an error evaluating JavaScript. It includes the usual
* message, and the raw JS stack where the error occurred (which may be empty).
*/
@DoNotStrip
public class JSException extends Exception {
private final String mStack;
@DoNotStrip
public JSException(String message, String stack, Throwable cause) {
super(message, cause);
mStack = stack;
}
public JSException(String message, String stack) {
super(message);
mStack = stack;
}
public String getStack() {
return mStack;
}
}