Skip to content

Commit 2f213c8

Browse files
committed
Fix a crash in Chain.terse and Chain.foldFrames.
These methods didn't gracefully handle a chain with an empty frame, which comes up occasionally in practice. Closes flutter#9 [email protected] Review URL: https://codereview.chromium.org//1492323004 .
1 parent 609425c commit 2f213c8

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.5.1
2+
3+
* Fix a crash in `Chain.foldFrames()` and `Chain.terse` when one of the chain's
4+
traces has no frames.
5+
16
## 1.5.0
27

38
* `new Chain.parse()` now parses all the stack trace formats supported by `new

lib/src/chain.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ typedef void ChainHandler(error, Chain chain);
3737
/// "$stackChain");
3838
/// });
3939
class Chain implements StackTrace {
40-
4140
/// The stack traces that make up this chain.
4241
///
4342
/// Like the frames in a stack trace, the traces are ordered from most local
@@ -155,6 +154,7 @@ class Chain implements StackTrace {
155154
var nonEmptyTraces = foldedTraces.where((trace) {
156155
// Ignore traces that contain only folded frames.
157156
if (trace.frames.length > 1) return true;
157+
if (trace.frames.isEmpty) return false;
158158

159159
// In terse mode, the trace may have removed an outer folded frame,
160160
// leaving a single non-folded frame. We can detect a folded frame because

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: stack_trace
77
#
88
# When the major version is upgraded, you *must* update that version constraint
99
# in pub to stay in sync with this.
10-
version: 1.5.0
10+
version: 1.5.1
1111
author: "Dart Team <[email protected]>"
1212
homepage: http://github.com/dart-lang/stack_trace
1313
description: >

test/chain/chain_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ void main() {
109109

110110
expect(chain.terse.toString(), equals('dart:core E.f\n'));
111111
});
112+
113+
// Regression test for #9
114+
test("doesn't crash on empty traces", () {
115+
var chain = new Chain([
116+
new Trace.parse('user/code.dart 10:11 Bang.qux'),
117+
new Trace([]),
118+
new Trace.parse('user/code.dart 10:11 Bang.qux')
119+
]);
120+
121+
expect(chain.terse.toString(), equals(
122+
'$userSlashCode 10:11 Bang.qux\n'
123+
'===== asynchronous gap ===========================\n'
124+
'$userSlashCode 10:11 Bang.qux\n'));
125+
});
112126
});
113127

114128
group('Chain.foldFrames', () {

0 commit comments

Comments
 (0)