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

Side by Side Diff: third_party/dart-packages/stack_trace/README.md

Issue 971083002: Create an apptesting framework for dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update upload_binaries.py to add the apptest.dartzip artifact. Created 5 years, 9 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
OLDNEW
(Empty)
1 This library provides the ability to parse, inspect, and manipulate stack traces
2 produced by the underlying Dart implementation. It also provides functions to
3 produce string representations of stack traces in a more readable format than
4 the native [StackTrace] implementation.
5
6 `Trace`s can be parsed from native [StackTrace]s using `Trace.from`, or captured
7 using `Trace.current`. Native [StackTrace]s can also be directly converted to
8 human-readable strings using `Trace.format`.
9
10 [StackTrace]: http://api.dartlang.org/docs/releases/latest/dart_core/StackTrace. html
11
12 Here's an example native stack trace from debugging this library:
13
14 #0 Object.noSuchMethod (dart:core-patch:1884:25)
15 #1 Trace.terse.<anonymous closure> (file:///usr/local/google-old/home/g oog/dart/dart/pkg/stack_trace/lib/src/trace.dart:47:21)
16 #2 IterableMixinWorkaround.reduce (dart:collection:29:29)
17 #3 List.reduce (dart:core-patch:1247:42)
18 #4 Trace.terse (file:///usr/local/google-old/home/goog/dart/dart/pkg/st ack_trace/lib/src/trace.dart:40:35)
19 #5 format (file:///usr/local/google-old/home/goog/dart/dart/pkg/stack_t race/lib/stack_trace.dart:24:28)
20 #6 main.<anonymous closure> (file:///usr/local/google-old/home/goog/dar t/dart/test.dart:21:29)
21 #7 _CatchErrorFuture._sendError (dart:async:525:24)
22 #8 _FutureImpl._setErrorWithoutAsyncTrace (dart:async:393:26)
23 #9 _FutureImpl._setError (dart:async:378:31)
24 #10 _ThenFuture._sendValue (dart:async:490:16)
25 #11 _FutureImpl._handleValue.<anonymous closure> (dart:async:349:28)
26 #12 Timer.run.<anonymous closure> (dart:async:2402:21)
27 #13 Timer.Timer.<anonymous closure> (dart:async-patch:15:15)
28
29 and its human-readable representation:
30
31 dart:core-patch Object.noSuchMethod
32 pkg/stack_trace/lib/src/trace.dart 47:21 Trace.terse.<fn>
33 dart:collection IterableMixinWorkaround.reduce
34 dart:core-patch List.reduce
35 pkg/stack_trace/lib/src/trace.dart 40:35 Trace.terse
36 pkg/stack_trace/lib/stack_trace.dart 24:28 format
37 test.dart 21:29 main.<fn>
38 dart:async _CatchErrorFuture._sendError
39 dart:async _FutureImpl._setErrorWithoutAsyn cTrace
40 dart:async _FutureImpl._setError
41 dart:async _ThenFuture._sendValue
42 dart:async _FutureImpl._handleValue.<fn>
43 dart:async Timer.run.<fn>
44 dart:async-patch Timer.Timer.<fn>
45
46 You can further clean up the stack trace using `Trace.terse`. This folds
47 together multiple stack frames from the Dart core libraries, so that only the
48 core library method that was directly called from user code is visible. For
49 example:
50
51 dart:core Object.noSuchMethod
52 pkg/stack_trace/lib/src/trace.dart 47:21 Trace.terse.<fn>
53 dart:core List.reduce
54 pkg/stack_trace/lib/src/trace.dart 40:35 Trace.terse
55 pkg/stack_trace/lib/stack_trace.dart 24:28 format
56 test.dart 21:29 main.<fn>
57 dart:async Timer.Timer.<fn>
58
59 ## Stack Chains
60
61 This library also provides the ability to capture "stack chains" with the
62 `Chain` class. When writing asynchronous code, a single stack trace isn't very
63 useful, since the call stack is unwound every time something async happens. A
64 stack chain tracks stack traces through asynchronous calls, so that you can see
65 the full path from `main` down to the error.
66
67 To use stack chains, just wrap the code that you want to track in
68 `Chain.capture`. This will create a new [Zone][] in which stack traces are
69 recorded and woven into chains every time an asynchronous call occurs. Zones are
70 sticky, too, so any asynchronous operations started in the `Chain.capture`
71 callback will have their chains tracked, as will asynchronous operations they
72 start and so on.
73
74 Here's an example of some code that doesn't capture its stack chains:
75
76 ```dart
77 import 'dart:async';
78
79 void main() {
80 scheduleAsync();
81 }
82
83 void scheduleAsync() {
84 return new Future.delayed(new Duration(seconds: 1))
85 .then((_) => runAsync());
86 }
87
88 void runAsync() {
89 throw 'oh no!';
90 }
91 ```
92
93 If we run this, it prints the following:
94
95 Uncaught Error: oh no!
96 Stack Trace:
97 #0 runAsync (file:///usr/local/google-old/home/goog/dart/dart/test.dart :13:3)
98 #1 scheduleAsync.<anonymous closure> (file:///usr/local/google-old/home /goog/dart/dart/test.dart:9:28)
99 #2 _rootRunUnary (dart:async/zone.dart:717)
100 #3 _RootZone.runUnary (dart:async/zone.dart:854)
101 #4 _Future._propagateToListeners.handleValueCallback (dart:async/future _impl.dart:488)
102 #5 _Future._propagateToListeners (dart:async/future_impl.dart:571)
103 #6 _Future._complete (dart:async/future_impl.dart:317)
104 #7 _SyncCompleter.complete (dart:async/future_impl.dart:44)
105 #8 Future.Future.delayed.<anonymous closure> (dart:async/future.dart:21 9)
106 #9 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart: 11)
107 #10 _handleTimeout (dart:io/timer_impl.dart:292)
108 #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch .dart:115)
109
110 Notice how there's no mention of `main` in that stack trace. All we know is that
111 the error was in `runAsync`; we don't know why `runAsync` was called.
112
113 Now let's look at the same code with stack chains captured:
114
115 ```dart
116 import 'dart:async';
117
118 import 'package:stack_trace/stack_trace.dart';
119
120 void main() {
121 Chain.capture(() {
122 scheduleAsync();
123 });
124 }
125
126 void scheduleAsync() {
127 new Future.delayed(new Duration(seconds: 1))
128 .then((_) => runAsync());
129 }
130
131 void runAsync() {
132 throw 'oh no!';
133 }
134 ```
135
136 Now if we run it, it prints this:
137
138 Uncaught Error: oh no!
139 Stack Trace:
140 test.dart 17:3 runAsync
141 test.dart 13:28 scheduleAsync. <fn>
142 package:stack_trace/src/stack_zone_specification.dart 129:26 registerUnaryC allback.<fn>.<fn>
143 package:stack_trace/src/stack_zone_specification.dart 174:15 StackZoneSpeci fication._run
144 package:stack_trace/src/stack_zone_specification.dart 177:7 StackZoneSpeci fication._run
145 package:stack_trace/src/stack_zone_specification.dart 175:7 StackZoneSpeci fication._run
146 package:stack_trace/src/stack_zone_specification.dart 129:18 registerUnaryC allback.<fn>
147 dart:async/zone.dart 717 _rootRunUnary
148 dart:async/zone.dart 449 _ZoneDelegate. runUnary
149 dart:async/zone.dart 654 _CustomizedZon e.runUnary
150 dart:async/future_impl.dart 488 _Future._propa gateToListeners.handleValueCallback
151 dart:async/future_impl.dart 571 _Future._propa gateToListeners
152 dart:async/future_impl.dart 317 _Future._compl ete
153 dart:async/future_impl.dart 44 _SyncCompleter .complete
154 dart:async/future.dart 219 Future.Future. delayed.<fn>
155 package:stack_trace/src/stack_zone_specification.dart 174:15 StackZoneSpeci fication._run
156 package:stack_trace/src/stack_zone_specification.dart 119:52 registerCallba ck.<fn>
157 dart:async/zone.dart 706 _rootRun
158 dart:async/zone.dart 440 _ZoneDelegate. run
159 dart:async/zone.dart 650 _CustomizedZon e.run
160 dart:async/zone.dart 561 _BaseZone.runG uarded
161 dart:async/zone.dart 586 _BaseZone.bind Callback.<fn>
162 package:stack_trace/src/stack_zone_specification.dart 174:15 StackZoneSpeci fication._run
163 package:stack_trace/src/stack_zone_specification.dart 119:52 registerCallba ck.<fn>
164 dart:async/zone.dart 710 _rootRun
165 dart:async/zone.dart 440 _ZoneDelegate. run
166 dart:async/zone.dart 650 _CustomizedZon e.run
167 dart:async/zone.dart 561 _BaseZone.runG uarded
168 dart:async/zone.dart 586 _BaseZone.bind Callback.<fn>
169 dart:async-patch/timer_patch.dart 11 _createTimer.< fn>
170 dart:io/timer_impl.dart 292 _handleTimeout
171 dart:isolate-patch/isolate_patch.dart 115 _RawReceivePor tImpl._handleMessage
172 ===== asynchronous gap ===========================
173 dart:async/zone.dart 476 _ZoneDelegate.registerUnaryCallba ck
174 dart:async/zone.dart 666 _CustomizedZone.registerUnaryCall back
175 dart:async/future_impl.dart 164 _Future._Future._then
176 dart:async/future_impl.dart 187 _Future.then
177 test.dart 13:12 scheduleAsync
178 test.dart 7:18 main.<fn>
179 dart:async/zone.dart 710 _rootRun
180 dart:async/zone.dart 440 _ZoneDelegate.run
181 dart:async/zone.dart 650 _CustomizedZone.run
182 dart:async/zone.dart 944 runZoned
183 package:stack_trace/src/chain.dart 93:20 Chain.capture
184 test.dart 6:16 main
185 dart:isolate-patch/isolate_patch.dart 216 _startIsolate.isolateStartHandler
186 dart:isolate-patch/isolate_patch.dart 115 _RawReceivePortImpl._handleMessag e
187
188 That's a lot of text! If you look closely, though, you can see that `main` is
189 listed in the first trace in the chain.
190
191 Thankfully, you can call `Chain.terse` just like `Trace.terse` to get rid of all
192 the frames you don't care about. The terse version of the stack chain above is
193 this:
194
195 test.dart 17:3 runAsync
196 test.dart 13:28 scheduleAsync.<fn>
197 dart:isolate _RawReceivePortImpl._handleMessage
198 ===== asynchronous gap ===========================
199 dart:async _Future.then
200 test.dart 13:12 scheduleAsync
201 test.dart 7:18 main.<fn>
202 package:stack_trace/src/chain.dart 93:20 Chain.capture
203 test.dart 6:16 main
204 dart:isolate _RawReceivePortImpl._handleMessage
205
206 That's a lot easier to understand!
207
208 [Zone]: https://api.dartlang.org/apidocs/channels/stable/#dart-async.Zone
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698