From 0b89b18b1bd85307110ae073ae0a291d9a534e0c Mon Sep 17 00:00:00 2001 From: Felix Oghina Date: Thu, 11 Feb 2016 04:36:16 -0800 Subject: [PATCH] format exceptions correctly when crashing Reviewed By: ivank Differential Revision: D2921881 fb-gh-sync-id: bd35ada33c752877dd3f6274ed8d4b4b7c851b9a shipit-source-id: bd35ada33c752877dd3f6274ed8d4b4b7c851b9a --- .../modules/core/ExceptionsManagerModule.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ExceptionsManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ExceptionsManagerModule.java index 876a2fca2..ca12dd6c5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/ExceptionsManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/ExceptionsManagerModule.java @@ -16,6 +16,7 @@ import com.facebook.react.bridge.BaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableType; import com.facebook.react.devsupport.DevSupportManager; import com.facebook.react.common.ReactConstants; @@ -32,16 +33,17 @@ public class ExceptionsManagerModule extends BaseJavaModule { return "RKExceptionsManager"; } - private String stackTraceToString(ReadableArray stack) { - StringBuilder stringBuilder = new StringBuilder(); + private String stackTraceToString(String message, ReadableArray stack) { + StringBuilder stringBuilder = new StringBuilder(message).append(", stack:\n"); for (int i = 0; i < stack.size(); i++) { ReadableMap frame = stack.getMap(i); - stringBuilder.append(frame.getString("methodName")); - stringBuilder.append("\n "); - stringBuilder.append(new File(frame.getString("file")).getName()); - stringBuilder.append(":"); - stringBuilder.append(frame.getInt("lineNumber")); - if (frame.hasKey("column") && !frame.isNull("column")) { + stringBuilder + .append(frame.getString("methodName")) + .append("@") + .append(frame.getInt("lineNumber")); + if (frame.hasKey("column") && + !frame.isNull("column") && + frame.getType("column") == ReadableType.Number) { stringBuilder .append(":") .append(frame.getInt("column")); @@ -58,14 +60,14 @@ public class ExceptionsManagerModule extends BaseJavaModule { @ReactMethod public void reportSoftException(String title, ReadableArray details, int exceptionId) { - FLog.e(ReactConstants.TAG, title + "\n" + stackTraceToString(details)); + FLog.e(ReactConstants.TAG, stackTraceToString(title, details)); } private void showOrThrowError(String title, ReadableArray details, int exceptionId) { if (mDevSupportManager.getDevSupportEnabled()) { mDevSupportManager.showNewJSError(title, details, exceptionId); } else { - throw new JavascriptException(stackTraceToString(details)); + throw new JavascriptException(stackTraceToString(title, details)); } }