Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: pkg/stack_trace/lib/src/chain.dart

Issue 556363004: Add an error callback to StackZoneSpecification. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/stack_trace/README.md ('k') | pkg/stack_trace/lib/src/stack_zone_specification.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library stack_trace.chain; 5 library stack_trace.chain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'frame.dart'; 10 import 'frame.dart';
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return callback(); 95 return callback();
96 } catch (error, stackTrace) { 96 } catch (error, stackTrace) {
97 // TODO(nweiz): Don't special-case this when issue 19566 is fixed. 97 // TODO(nweiz): Don't special-case this when issue 19566 is fixed.
98 return Zone.current.handleUncaughtError(error, stackTrace); 98 return Zone.current.handleUncaughtError(error, stackTrace);
99 } 99 }
100 }, zoneSpecification: spec.toSpec(), zoneValues: { 100 }, zoneSpecification: spec.toSpec(), zoneValues: {
101 #stack_trace.stack_zone.spec: spec 101 #stack_trace.stack_zone.spec: spec
102 }); 102 });
103 } 103 }
104 104
105 /// Ensures that any errors emitted by [futureOrStream] have the correct stack 105 /// Returns [futureOrStream] unmodified.
106 /// chain information associated with them.
107 /// 106 ///
108 /// For the most part an error thrown within a [capture] zone will have the 107 /// Prior to Dart 1.7, this was necessary to ensure that stack traces for
109 /// correct stack chain automatically associated with it. However, there are 108 /// exceptions reported with [Completer.completeError] and
110 /// some cases where exceptions won't be automatically detected: any [Future] 109 /// [StreamController.addError] were tracked correctly.
111 /// constructor, [Completer.completeError], [Stream.addError], and libraries 110 @Deprecated("Chain.track is not necessary in Dart 1.7+.")
112 /// that use these. 111 static track(futureOrStream) => futureOrStream;
113 ///
114 /// This returns a [Future] or [Stream] that will emit the same values and
115 /// errors as [futureOrStream]. The only exception is that if [futureOrStream]
116 /// emits an error without a stack trace, one will be added in the return
117 /// value.
118 ///
119 /// If this is called outside of a [capture] zone, it just returns
120 /// [futureOrStream] as-is.
121 ///
122 /// As the name suggests, [futureOrStream] may be either a [Future] or a
123 /// [Stream].
124 static track(futureOrStream) {
125 if (_currentSpec == null) return futureOrStream;
126 if (futureOrStream is Future) {
127 return _currentSpec.trackFuture(futureOrStream, 1);
128 } else {
129 return _currentSpec.trackStream(futureOrStream, 1);
130 }
131 }
132 112
133 /// Returns the current stack chain. 113 /// Returns the current stack chain.
134 /// 114 ///
135 /// By default, the first frame of the first trace will be the line where 115 /// By default, the first frame of the first trace will be the line where
136 /// [Chain.current] is called. If [level] is passed, the first trace will 116 /// [Chain.current] is called. If [level] is passed, the first trace will
137 /// start that many frames up instead. 117 /// start that many frames up instead.
138 /// 118 ///
139 /// If this is called outside of a [capture] zone, it just returns a 119 /// If this is called outside of a [capture] zone, it just returns a
140 /// single-trace chain. 120 /// single-trace chain.
141 factory Chain.current([int level=0]) { 121 factory Chain.current([int level=0]) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 194 }
215 195
216 /// Converts [this] to a [Trace]. 196 /// Converts [this] to a [Trace].
217 /// 197 ///
218 /// The trace version of a chain is just the concatenation of all the traces 198 /// The trace version of a chain is just the concatenation of all the traces
219 /// in the chain. 199 /// in the chain.
220 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); 200 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames)));
221 201
222 String toString() => traces.join(_GAP); 202 String toString() => traces.join(_GAP);
223 } 203 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/README.md ('k') | pkg/stack_trace/lib/src/stack_zone_specification.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698