|
22 | 22 | */
|
23 | 23 | public class StackTraceHelper {
|
24 | 24 |
|
| 25 | + public static final java.lang.String COLUMN_KEY = "column"; |
| 26 | + public static final java.lang.String LINE_NUMBER_KEY = "lineNumber"; |
| 27 | + |
25 | 28 | /**
|
26 | 29 | * Represents a generic entry in a stack trace, be it originally from JS or Java.
|
27 | 30 | */
|
@@ -101,10 +104,13 @@ public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
|
101 | 104 | ReadableMap frame = stack.getMap(i);
|
102 | 105 | String methodName = frame.getString("methodName");
|
103 | 106 | String fileName = frame.getString("file");
|
104 |
| - int lineNumber = frame.getInt("lineNumber"); |
| 107 | + int lineNumber = -1; |
| 108 | + if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) { |
| 109 | + lineNumber = frame.getInt(LINE_NUMBER_KEY); |
| 110 | + } |
105 | 111 | int columnNumber = -1;
|
106 |
| - if (frame.hasKey("column") && !frame.isNull("column")) { |
107 |
| - columnNumber = frame.getInt("column"); |
| 112 | + if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) { |
| 113 | + columnNumber = frame.getInt(COLUMN_KEY); |
108 | 114 | }
|
109 | 115 | result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber);
|
110 | 116 | }
|
@@ -132,12 +138,17 @@ public static StackFrame[] convertJavaStackTrace(Throwable exception) {
|
132 | 138 | * Format a {@link StackFrame} to a String (method name is not included).
|
133 | 139 | */
|
134 | 140 | public static String formatFrameSource(StackFrame frame) {
|
135 |
| - String lineInfo = ""; |
136 |
| - final int column = frame.getColumn(); |
137 |
| - // If the column is 0, don't show it in red box. |
138 |
| - final String columnString = column <= 0 ? "" : ":" + column; |
139 |
| - lineInfo += frame.getFileName() + ":" + frame.getLine() + columnString; |
140 |
| - return lineInfo; |
| 141 | + StringBuilder lineInfo = new StringBuilder(); |
| 142 | + lineInfo.append(frame.getFileName()); |
| 143 | + final int line = frame.getLine(); |
| 144 | + if (line > 0) { |
| 145 | + lineInfo.append(":").append(line); |
| 146 | + final int column = frame.getColumn(); |
| 147 | + if (column > 0) { |
| 148 | + lineInfo.append(":").append(column); |
| 149 | + } |
| 150 | + } |
| 151 | + return lineInfo.toString(); |
141 | 152 | }
|
142 | 153 |
|
143 | 154 | /**
|
|
0 commit comments