Skip to content

Commit 8a63538

Browse files
authored
Handle V8 stack trace with no description line(s) (#2220)
1 parent ce12670 commit 8a63538

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

pkgs/stack_trace/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.12.2-dev
2+
3+
* Relax parsing of V8 traces to allow a missing initial description.
4+
15
## 1.12.1
26

37
* Move to `dart-lang/tools` monorepo.

pkgs/stack_trace/lib/src/trace.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ final _terseRegExp = RegExp(r'(-patch)?([/\\].*)?$');
1919
/// description of the exception that occurred. That description can be multiple
2020
/// lines, so we just look for any line other than the first that begins with
2121
/// three or four spaces and "at".
22-
final _v8Trace = RegExp(r'\n ?at ');
22+
///
23+
/// Sometimes the first line is empty, and sometimes the empty line gets
24+
/// trimmed, so also accept a missing description line.
25+
final _v8Trace = RegExp(r'(?:^|\n) ?at ');
2326

2427
/// A RegExp to match indidual lines of V8's stack traces.
2528
///
@@ -175,7 +178,6 @@ class Trace implements StackTrace {
175178
: this(
176179
trace
177180
.split('\n')
178-
.skip(1)
179181
// It's possible that an Exception's description contains a line
180182
// that looks like a V8 trace line, which will screw this up.
181183
// Unfortunately, that's impossible to detect.

pkgs/stack_trace/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: stack_trace
2-
version: 1.12.1
2+
version: 1.12.2-wip
33
description: A package for manipulating stack traces and printing them readably.
44
repository: https://github.com/dart-lang/tools/tree/main/pkgs/stack_trace
55
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Astack_trace

pkgs/stack_trace/test/trace_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ void main() {
9090
expect(
9191
trace.frames[2].uri, equals(Uri.parse('https://pub.dev/thing.js')));
9292
expect(trace.frames[2].member, equals('<fn>.zip.zap'));
93+
94+
// Missing description line
95+
trace =
96+
Trace.parse(' at Foo._bar (https://example.com/stuff.js:42:21)\n'
97+
' at https://example.com/stuff.js:0:2\n'
98+
' at (anonymous function).zip.zap '
99+
'(https://pub.dev/thing.js:1:100)');
100+
101+
expect(trace.frames[0].uri,
102+
equals(Uri.parse('https://example.com/stuff.js')));
103+
expect(trace.frames[1].uri,
104+
equals(Uri.parse('https://example.com/stuff.js')));
105+
expect(trace.frames[1].member, equals('<fn>'));
106+
expect(
107+
trace.frames[2].uri, equals(Uri.parse('https://pub.dev/thing.js')));
108+
expect(trace.frames[2].member, equals('<fn>.zip.zap'));
93109
});
94110

95111
// JavaScriptCore traces are just like V8, except that it doesn't have a

0 commit comments

Comments
 (0)