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

Side by Side Diff: pkg/analysis_server/lib/driver.dart

Issue 811223002: Capture and report uncaught exceptions in server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | « no previous file | pkg/analysis_server/lib/src/analysis_server.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 driver; 5 library driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:analysis_server/http_server.dart'; 10 import 'package:analysis_server/http_server.dart';
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 AnalysisEngine.instance.instrumentationService = service; 222 AnalysisEngine.instance.instrumentationService = service;
223 223
224 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service); 224 socketServer = new SocketServer(analysisServerOptions, defaultSdk, service);
225 httpServer = new HttpAnalysisServer(socketServer); 225 httpServer = new HttpAnalysisServer(socketServer);
226 stdioServer = new StdioAnalysisServer(socketServer); 226 stdioServer = new StdioAnalysisServer(socketServer);
227 227
228 if (serve_http) { 228 if (serve_http) {
229 httpServer.serveHttp(port); 229 httpServer.serveHttp(port);
230 } 230 }
231 231
232 if (results[INTERNAL_PRINT_TO_CONSOLE]) { 232 if (results[INTERNAL_PRINT_TO_CONSOLE]) {
Paul Berry 2014/12/18 18:57:38 Consider getting rid of the code duplication with:
Brian Wilkerson 2014/12/19 15:55:01 Done
233 stdioServer.serveStdio().then((_) { 233 _captureExceptions(() {
234 if (serve_http) {
235 httpServer.close();
236 }
237 service.shutdown();
238 exit(0);
239 });
240 } else {
241 _capturePrints(() {
242 stdioServer.serveStdio().then((_) { 234 stdioServer.serveStdio().then((_) {
243 if (serve_http) { 235 if (serve_http) {
244 httpServer.close(); 236 httpServer.close();
237 }
238 service.shutdown();
239 exit(0);
240 });
241 });
242 } else {
243 _captureExceptions(() {
244 stdioServer.serveStdio().then((_) {
245 if (serve_http) {
246 httpServer.close();
245 } 247 }
246 service.shutdown(); 248 service.shutdown();
247 exit(0); 249 exit(0);
248 }); 250 });
249 }, httpServer.recordPrint); 251 }, print: httpServer.recordPrint);
250 } 252 }
251 } 253 }
252 254
253 /** 255 /**
254 * Execute [callback], capturing any data it prints out and redirecting it to 256 * Execute the given [callback], capturing any unhandled exceptions and
255 * the function [printHandler]. 257 * reporting them to the client. If a [printHandler] function is provided,
258 * then also capture any data printed by the callback and redirect it to the
259 * [printHandler].
256 */ 260 */
257 dynamic _capturePrints(dynamic callback(), void printHandler(String line)) { 261 dynamic _captureExceptions(dynamic callback(), {void print(String line)}) {
258 ZoneSpecification zoneSpecification = new ZoneSpecification( 262 ZoneSpecification zoneSpecification = new ZoneSpecification(
259 print: (Zone self, ZoneDelegate parent, Zone zone, String line) { 263 handleUncaughtError: (Zone self, ZoneDelegate parent, Zone zone,
260 printHandler(line); 264 dynamic exception, StackTrace stackTrace) {
265 socketServer.analysisServer.reportException(exception, stackTrace);
266 throw exception;
267 }, print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
268 print(line);
Paul Berry 2014/12/18 18:57:38 Won't this lead to a null reference exception if t
Brian Wilkerson 2014/12/19 15:55:01 Done
261 // Note: we don't pass the line on to stdout, because that is reserved 269 // Note: we don't pass the line on to stdout, because that is reserved
262 // for communication to the client. 270 // for communication to the client.
263 }); 271 });
264 return runZoned(callback, zoneSpecification: zoneSpecification); 272 return runZoned(callback, zoneSpecification: zoneSpecification);
265 } 273 }
266 274
267 /** 275 /**
268 * Print information about how to use the server. 276 * Print information about how to use the server.
269 */ 277 */
270 void _printUsage(ArgParser parser) { 278 void _printUsage(ArgParser parser) {
271 print('Usage: $BINARY_NAME [flags]'); 279 print('Usage: $BINARY_NAME [flags]');
272 print(''); 280 print('');
273 print('Supported flags are:'); 281 print('Supported flags are:');
274 print(parser.usage); 282 print(parser.usage);
275 } 283 }
276 } 284 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/analysis_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698