diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/StackTraceHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/StackTraceHelper.java index 75ca90d532911f..3e66d52e61acac 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/StackTraceHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/StackTraceHelper.java @@ -28,8 +28,10 @@ public class StackTraceHelper { public static final java.lang.String COLUMN_KEY = "column"; public static final java.lang.String LINE_NUMBER_KEY = "lineNumber"; - private static final Pattern STACK_FRAME_PATTERN = Pattern.compile( + private static final Pattern STACK_FRAME_PATTERN1 = Pattern.compile( "^(?:(.*?)@)?(.*?)\\:([0-9]+)\\:([0-9]+)$"); + private static final Pattern STACK_FRAME_PATTERN2 = Pattern.compile( + "\\s*(?:at)\\s*(.+?)\\s*[@(](.*):([0-9]+):([0-9]+)[)]$"); /** * Represents a generic entry in a stack trace, be it originally from JS or Java. @@ -175,16 +177,22 @@ public static StackFrame[] convertJsStackTrace(String stack) { String[] stackTrace = stack.split("\n"); StackFrame[] result = new StackFrame[stackTrace.length]; for (int i = 0; i < stackTrace.length; ++i) { - Matcher matcher = STACK_FRAME_PATTERN.matcher(stackTrace[i]); - if (matcher.find()) { - result[i] = new StackFrameImpl( - matcher.group(2), - matcher.group(1) == null ? "(unknown)" : matcher.group(1), - Integer.parseInt(matcher.group(3)), - Integer.parseInt(matcher.group(4))); + Matcher matcher1 = STACK_FRAME_PATTERN1.matcher(stackTrace[i]); + Matcher matcher2 = STACK_FRAME_PATTERN2.matcher(stackTrace[i]); + Matcher matcher; + if (matcher2.find()) { + matcher = matcher2; + } else if (matcher1.find()) { + matcher = matcher1; } else { result[i] = new StackFrameImpl(null, stackTrace[i], -1, -1); + continue; } + result[i] = new StackFrameImpl( + matcher.group(2), + matcher.group(1) == null ? "(unknown)" : matcher.group(1), + Integer.parseInt(matcher.group(3)), + Integer.parseInt(matcher.group(4))); } return result; } diff --git a/ReactAndroid/src/test/java/com/facebook/react/devsupport/StackTraceHelperTest.java b/ReactAndroid/src/test/java/com/facebook/react/devsupport/StackTraceHelperTest.java index b348bd14995dc3..70b64184bcb504 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/devsupport/StackTraceHelperTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/devsupport/StackTraceHelperTest.java @@ -17,6 +17,16 @@ @RunWith(RobolectricTestRunner.class) public class StackTraceHelperTest { + @Test + public void testParseAlternateFormatStackFrameWithMethod() { + final StackFrame frame = StackTraceHelper.convertJsStackTrace( + "at func1 (/path/to/file.js:2:18)")[0]; + assertThat(frame.getMethod()).isEqualTo("func1"); + assertThat(frame.getFileName()).isEqualTo("file.js"); + assertThat(frame.getLine()).isEqualTo(2); + assertThat(frame.getColumn()).isEqualTo(18); + } + @Test public void testParseStackFrameWithMethod() { final StackFrame frame = StackTraceHelper.convertJsStackTrace(