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

Side by Side Diff: runtime/observatory/lib/src/app/application.dart

Issue 1120133002: Rework error handling in the service protocol and in Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
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 part of app; 5 part of app;
6 6
7 class Notification {
8 Notification.fromEvent(this.event);
9 Notification.fromException(this.exception, this.stacktrace);
10
11 ServiceEvent event;
12 var exception;
13 var stacktrace;
14 }
15
7 /// The observatory application. Instances of this are created and owned 16 /// The observatory application. Instances of this are created and owned
8 /// by the observatory_application custom element. 17 /// by the observatory_application custom element.
9 class ObservatoryApplication extends Observable { 18 class ObservatoryApplication extends Observable {
10 static ObservatoryApplication app; 19 static ObservatoryApplication app;
11 final _pageRegistry = new List<Page>(); 20 final _pageRegistry = new List<Page>();
12 LocationManager _locationManager; 21 LocationManager _locationManager;
13 LocationManager get locationManager => _locationManager; 22 LocationManager get locationManager => _locationManager;
14 @observable Page currentPage; 23 @observable Page currentPage;
15 VM _vm; 24 VM _vm;
16 VM get vm => _vm; 25 VM get vm => _vm;
(...skipping 15 matching lines...) Expand all
32 targets.add(vm.target); 41 targets.add(vm.target);
33 } 42 }
34 _removeDisconnectEvents(); 43 _removeDisconnectEvents();
35 }); 44 });
36 45
37 vm.onDisconnect.then((String reason) { 46 vm.onDisconnect.then((String reason) {
38 if (this.vm != vm) { 47 if (this.vm != vm) {
39 // This disconnect event occured *after* a new VM was installed. 48 // This disconnect event occured *after* a new VM was installed.
40 return; 49 return;
41 } 50 }
42 notifications.add(new ServiceEvent.connectionClosed(reason)); 51 notifications.add(
52 new Notification.fromEvent(
53 new ServiceEvent.connectionClosed(reason)));
43 }); 54 });
44 55
45 vm.errors.stream.listen(_onError);
46 vm.events.stream.listen(_onEvent); 56 vm.events.stream.listen(_onEvent);
47 vm.exceptions.stream.listen(_onException);
48 } 57 }
49 _vm = vm; 58 _vm = vm;
50 } 59 }
51 final TargetManager targets; 60 final TargetManager targets;
52 @reflectable final ObservatoryApplicationElement rootElement; 61 @reflectable final ObservatoryApplicationElement rootElement;
53 62
54 TraceViewElement _traceView = null; 63 TraceViewElement _traceView = null;
55 64
56 @reflectable ServiceObject lastErrorOrException; 65 @reflectable ServiceObject lastErrorOrException;
57 @observable ObservableList<ServiceEvent> notifications = 66 @observable ObservableList<Notification> notifications =
58 new ObservableList<ServiceEvent>(); 67 new ObservableList<Notification>();
59 68
60 void _initOnce() { 69 void _initOnce() {
61 assert(app == null); 70 assert(app == null);
62 app = this; 71 app = this;
63 _registerPages(); 72 _registerPages();
64 Analytics.initialize(); 73 Analytics.initialize();
65 // Visit the current page. 74 // Visit the current page.
66 locationManager._visit(); 75 locationManager._visit();
67 } 76 }
68 77
69 void removePauseEvents(Isolate isolate) { 78 void removePauseEvents(Isolate isolate) {
70 bool isPauseEvent(var event) { 79 bool isPauseEvent(ServiceEvent event) {
Cutch 2015/05/13 17:50:09 this method should be on event.
turnidge 2015/05/14 17:53:42 Done.
71 return (event.eventType == ServiceEvent.kPauseStart || 80 return (event.eventType == ServiceEvent.kPauseStart ||
72 event.eventType == ServiceEvent.kPauseExit || 81 event.eventType == ServiceEvent.kPauseExit ||
73 event.eventType == ServiceEvent.kPauseBreakpoint || 82 event.eventType == ServiceEvent.kPauseBreakpoint ||
74 event.eventType == ServiceEvent.kPauseInterrupted || 83 event.eventType == ServiceEvent.kPauseInterrupted ||
75 event.eventType == ServiceEvent.kPauseException); 84 event.eventType == ServiceEvent.kPauseException);
76 } 85 }
77 86
78 notifications.removeWhere((oldEvent) { 87 notifications.removeWhere((notification) {
79 return (oldEvent.isolate == isolate && 88 var event = notification.event;
80 isPauseEvent(oldEvent)); 89 return (event != null &&
90 event.isolate == isolate &&
91 isPauseEvent(event));
81 }); 92 });
82 } 93 }
83 94
84 void _onEvent(ServiceEvent event) { 95 void _onEvent(ServiceEvent event) {
85 switch(event.eventType) { 96 switch(event.eventType) {
86 case ServiceEvent.kIsolateStart: 97 case ServiceEvent.kIsolateStart:
87 case ServiceEvent.kIsolateUpdate: 98 case ServiceEvent.kIsolateUpdate:
88 case ServiceEvent.kGraph: 99 case ServiceEvent.kGraph:
89 case ServiceEvent.kBreakpointAdded: 100 case ServiceEvent.kBreakpointAdded:
90 case ServiceEvent.kBreakpointResolved: 101 case ServiceEvent.kBreakpointResolved:
91 case ServiceEvent.kBreakpointRemoved: 102 case ServiceEvent.kBreakpointRemoved:
92 case ServiceEvent.kGC: 103 case ServiceEvent.kGC:
93 // Ignore for now. 104 // Ignore for now.
94 break; 105 break;
95 106
96 case ServiceEvent.kIsolateExit: 107 case ServiceEvent.kIsolateExit:
97 case ServiceEvent.kResume: 108 case ServiceEvent.kResume:
98 removePauseEvents(event.isolate); 109 removePauseEvents(event.isolate);
99 break; 110 break;
100 111
101 case ServiceEvent.kPauseStart: 112 case ServiceEvent.kPauseStart:
102 case ServiceEvent.kPauseExit: 113 case ServiceEvent.kPauseExit:
103 case ServiceEvent.kPauseBreakpoint: 114 case ServiceEvent.kPauseBreakpoint:
104 case ServiceEvent.kPauseInterrupted: 115 case ServiceEvent.kPauseInterrupted:
105 case ServiceEvent.kPauseException: 116 case ServiceEvent.kPauseException:
106 removePauseEvents(event.isolate); 117 removePauseEvents(event.isolate);
107 notifications.add(event); 118 notifications.add(new Notification.fromEvent(event));
108 break; 119 break;
109 120
110 case ServiceEvent.kInspect: 121 case ServiceEvent.kInspect:
111 notifications.add(event); 122 notifications.add(new Notification.fromEvent(event));
112 break; 123 break;
113 124
114 default: 125 default:
115 // Ignore unrecognized events. 126 // Ignore unrecognized events.
116 Logger.root.severe('Unrecognized event: $event'); 127 Logger.root.severe('Unrecognized event: $event');
117 break; 128 break;
118 } 129 }
119 } 130 }
120 131
121 void _registerPages() { 132 void _registerPages() {
122 _pageRegistry.add(new VMPage(this)); 133 _pageRegistry.add(new VMPage(this));
123 _pageRegistry.add(new FlagsPage(this)); 134 _pageRegistry.add(new FlagsPage(this));
124 _pageRegistry.add(new InspectPage(this)); 135 _pageRegistry.add(new InspectPage(this));
125 _pageRegistry.add(new ClassTreePage(this)); 136 _pageRegistry.add(new ClassTreePage(this));
126 _pageRegistry.add(new DebuggerPage(this)); 137 _pageRegistry.add(new DebuggerPage(this));
127 _pageRegistry.add(new CpuProfilerPage(this)); 138 _pageRegistry.add(new CpuProfilerPage(this));
128 _pageRegistry.add(new TableCpuProfilerPage(this)); 139 _pageRegistry.add(new TableCpuProfilerPage(this));
129 _pageRegistry.add(new AllocationProfilerPage(this)); 140 _pageRegistry.add(new AllocationProfilerPage(this));
130 _pageRegistry.add(new HeapMapPage(this)); 141 _pageRegistry.add(new HeapMapPage(this));
131 _pageRegistry.add(new VMConnectPage(this)); 142 _pageRegistry.add(new VMConnectPage(this));
132 _pageRegistry.add(new IsolateReconnectPage(this)); 143 _pageRegistry.add(new IsolateReconnectPage(this));
133 _pageRegistry.add(new ErrorViewPage(this)); 144 _pageRegistry.add(new ErrorViewPage(this));
134 _pageRegistry.add(new MetricsPage(this)); 145 _pageRegistry.add(new MetricsPage(this));
135 // Note that ErrorPage must be the last entry in the list as it is 146 // Note that ErrorPage must be the last entry in the list as it is
136 // the catch all. 147 // the catch all.
137 _pageRegistry.add(new ErrorPage(this)); 148 _pageRegistry.add(new ErrorPage(this));
138 } 149 }
139 150
140 void _onError(ServiceError error) {
141 lastErrorOrException = error;
142 _visit(Uri.parse('error/'), null);
143 }
144
145 void _onException(ServiceException exception) {
146 lastErrorOrException = exception;
147 if (exception.kind == 'NetworkException') {
148 // Got a network exception, visit the vm-connect page.
149 this.vm = null;
150 locationManager.go(locationManager.makeLink('/vm-connect'));
151 } else {
152 _visit(Uri.parse('error/'), {});
153 }
154 }
155
156 void _visit(Uri uri, Map internalArguments) { 151 void _visit(Uri uri, Map internalArguments) {
157 if (internalArguments['trace'] != null) { 152 if (internalArguments['trace'] != null) {
158 var traceArg = internalArguments['trace']; 153 var traceArg = internalArguments['trace'];
159 if (traceArg == 'on') { 154 if (traceArg == 'on') {
160 Tracer.start(); 155 Tracer.start();
161 } else if (traceArg == 'off') { 156 } else if (traceArg == 'off') {
162 Tracer.stop(); 157 Tracer.stop();
163 } 158 }
164 } 159 }
165 if (Tracer.current != null) { 160 if (Tracer.current != null) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 206 }
212 207
213 ObservatoryApplication(this.rootElement) : 208 ObservatoryApplication(this.rootElement) :
214 targets = new TargetManager() { 209 targets = new TargetManager() {
215 _locationManager = new LocationManager(this); 210 _locationManager = new LocationManager(this);
216 vm = new WebSocketVM(targets.defaultTarget); 211 vm = new WebSocketVM(targets.defaultTarget);
217 _initOnce(); 212 _initOnce();
218 } 213 }
219 214
220 void _removeDisconnectEvents() { 215 void _removeDisconnectEvents() {
221 notifications.removeWhere((oldEvent) { 216 notifications.removeWhere((notification) {
222 return (oldEvent.eventType == ServiceEvent.kConnectionClosed); 217 var event = notification.event;
218 return (event != null &&
219 event.eventType == ServiceEvent.kConnectionClosed);
223 }); 220 });
224 } 221 }
225 222
226 loadCrashDump(Map crashDump) { 223 loadCrashDump(Map crashDump) {
227 this.vm = new FakeVM(crashDump['result']); 224 this.vm = new FakeVM(crashDump['result']);
228 app.locationManager.go('#/vm'); 225 app.locationManager.go('#/vm');
229 } 226 }
227
228 void handleException(e, st) {
229 // TODO(turnidge): Report this failure via analytics.
230 Logger.root.warning('Caught exception: ${e}\n${st}');
231 notifications.add(new Notification.fromException(e, st));
232 }
230 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698