Support "..." VM frames in pkg/stack_trace. Also include the original stack trace when a parse error occurs. R=rnystrom@google.com Review URL: https://codereview.chromium.org//23133004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/stack_trace@26132 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/stack_trace/lib/src/frame.dart b/pkgs/stack_trace/lib/src/frame.dart index 5a0582c..3db4ab5 100644 --- a/pkgs/stack_trace/lib/src/frame.dart +++ b/pkgs/stack_trace/lib/src/frame.dart
@@ -97,6 +97,12 @@ /// Parses a string representation of a Dart VM stack frame. factory Frame.parseVM(String frame) { + // The VM sometimes folds multiple stack frames together and replaces them + // with "...". + if (frame == '...') { + return new Frame(new Uri(), null, null, '...'); + } + var match = _vmFrame.firstMatch(frame); if (match == null) { throw new FormatException("Couldn't parse VM stack trace line '$frame'.");
diff --git a/pkgs/stack_trace/lib/src/trace.dart b/pkgs/stack_trace/lib/src/trace.dart index 6b7da75..863d64e 100644 --- a/pkgs/stack_trace/lib/src/trace.dart +++ b/pkgs/stack_trace/lib/src/trace.dart
@@ -72,14 +72,19 @@ /// [trace] should be formatted in the same way as a Dart VM or browser stack /// trace. factory Trace.parse(String trace) { - if (trace.isEmpty) return new Trace(<Frame>[]); - if (trace.startsWith("Error\n")) return new Trace.parseV8(trace); - if (trace.contains(_firefoxTrace)) return new Trace.parseFirefox(trace); - if (trace.contains(_friendlyTrace)) return new Trace.parseFriendly(trace); + try { + if (trace.isEmpty) return new Trace(<Frame>[]); + if (trace.startsWith("Error\n")) return new Trace.parseV8(trace); + if (trace.contains(_firefoxTrace)) return new Trace.parseFirefox(trace); + if (trace.contains(_friendlyTrace)) return new Trace.parseFriendly(trace); - // Default to parsing the stack trace as a VM trace. This is also hit on IE - // and Safari, where the stack trace is just an empty string (issue 11257). - return new Trace.parseVM(trace); + // Default to parsing the stack trace as a VM trace. This is also hit on + // IE and Safari, where the stack trace is just an empty string (issue + // 11257). + return new Trace.parseVM(trace); + } on FormatException catch (error) { + throw new FormatException('${error.message}\nStack trace:\n$trace'); + } } /// Parses a string representation of a Dart VM stack trace.
diff --git a/pkgs/stack_trace/test/frame_test.dart b/pkgs/stack_trace/test/frame_test.dart index 75302a7..0be717d 100644 --- a/pkgs/stack_trace/test/frame_test.dart +++ b/pkgs/stack_trace/test/frame_test.dart
@@ -29,6 +29,15 @@ equals('<fn>.<fn>.bar')); }); + test('parses a folded frame correctly', () { + var frame = new Frame.parseVM('...'); + + expect(frame.member, equals('...')); + expect(frame.uri, equals(new Uri())); + expect(frame.line, isNull); + expect(frame.column, isNull); + }); + test('throws a FormatException for malformed frames', () { expect(() => new Frame.parseVM(''), throwsFormatException); expect(() => new Frame.parseVM('#1'), throwsFormatException);