Avoid overwriting chain for trace if one exists (#37)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 18ffda8..2627e71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.9.1
+* Preserve the original chain for a trace to handle cases where an
+ error is rethrown.
+
## 1.9.0
* Add an `errorZone` parameter to `Chain.capture()` that makes it avoid creating
diff --git a/lib/src/stack_zone_specification.dart b/lib/src/stack_zone_specification.dart
index 5be8dd3..6c31d12 100644
--- a/lib/src/stack_zone_specification.dart
+++ b/lib/src/stack_zone_specification.dart
@@ -208,7 +208,10 @@
try {
return f();
} catch (e, stackTrace) {
- _chains[stackTrace] = node;
+ // We can see the same stack trace multiple times if it's rethrown through
+ // guarded callbacks. The innermost chain will have the most
+ // information so it should take precedence.
+ _chains[stackTrace] ??= node;
rethrow;
} finally {
_currentNode = previousNode;
diff --git a/pubspec.yaml b/pubspec.yaml
index 3218be1..f7c562d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -7,7 +7,7 @@
#
# When the major version is upgraded, you *must* update that version constraint
# in pub to stay in sync with this.
-version: 1.9.0
+version: 1.9.1
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/stack_trace
description: A package for manipulating stack traces and printing them readably.