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

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

Issue 854443002: Catch and report exceptions in computers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | « no previous file | pkg/analysis_server/lib/src/operation/operation_analysis.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 analysis.server; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/analysis_logger.dart'; 10 import 'package:analysis_server/src/analysis_logger.dart';
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString ()); 505 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString ());
506 if (stackTrace != null) { 506 if (stackTrace != null) {
507 error.stackTrace = stackTrace.toString(); 507 error.stackTrace = stackTrace.toString();
508 } 508 }
509 Response response = new Response(request.id, error: error); 509 Response response = new Response(request.id, error: error);
510 channel.sendResponse(response); 510 channel.sendResponse(response);
511 return; 511 return;
512 } 512 }
513 } 513 }
514 channel.sendResponse(new Response.unknownRequest(request)); 514 channel.sendResponse(new Response.unknownRequest(request));
515 }, onError: _sendServerErrorNotification); 515 }, onError: sendServerErrorNotification);
516 } 516 }
517 517
518 /** 518 /**
519 * Returns `true` if there is a subscription for the given [server] and [file] . 519 * Returns `true` if there is a subscription for the given [server] and [file] .
520 */ 520 */
521 bool hasAnalysisSubscription(AnalysisService service, String file) { 521 bool hasAnalysisSubscription(AnalysisService service, String file) {
522 Set<String> files = analysisServices[service]; 522 Set<String> files = analysisServices[service];
523 return files != null && files.contains(file); 523 return files != null && files.contains(file);
524 } 524 }
525 525
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // perform the operation 596 // perform the operation
597 try { 597 try {
598 operation.perform(this); 598 operation.perform(this);
599 } catch (exception, stackTrace) { 599 } catch (exception, stackTrace) {
600 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}"); 600 AnalysisEngine.instance.logger.logError("${exception}\n${stackTrace}");
601 if (rethrowExceptions) { 601 if (rethrowExceptions) {
602 throw new AnalysisException( 602 throw new AnalysisException(
603 'Unexpected exception during analysis', 603 'Unexpected exception during analysis',
604 new CaughtException(exception, stackTrace)); 604 new CaughtException(exception, stackTrace));
605 } 605 }
606 _sendServerErrorNotification(exception, stackTrace); 606 sendServerErrorNotification(exception, stackTrace);
607 shutdown(); 607 shutdown();
608 } finally { 608 } finally {
609 if (!operationQueue.isEmpty) { 609 if (!operationQueue.isEmpty) {
610 _schedulePerformOperation(); 610 _schedulePerformOperation();
611 } else { 611 } else {
612 sendStatusNotification(null); 612 sendStatusNotification(null);
613 _onAnalysisCompleteController.add(null); 613 _onAnalysisCompleteController.add(null);
614 } 614 }
615 } 615 }
616 } 616 }
617 617
618 /** 618 /**
619 * Trigger reanalysis of all files from disk. 619 * Trigger reanalysis of all files from disk.
620 */ 620 */
621 void reanalyze() { 621 void reanalyze() {
622 // Clear any operations that are pending. 622 // Clear any operations that are pending.
623 operationQueue.clear(); 623 operationQueue.clear();
624 // Instruct the contextDirectoryManager to rebuild all contexts from 624 // Instruct the contextDirectoryManager to rebuild all contexts from
625 // scratch. 625 // scratch.
626 contextDirectoryManager.refresh(); 626 contextDirectoryManager.refresh();
627 } 627 }
628 628
629 /** 629 /**
630 * Report to the client that the given [exception] was caught with the
631 * associated [stackTrace].
632 */
633 void reportException(dynamic exception, StackTrace stackTrace) {
634 _sendServerErrorNotification(exception, stackTrace);
635 }
636
637 /**
638 * Schedules execution of the given [ServerOperation]. 630 * Schedules execution of the given [ServerOperation].
639 */ 631 */
640 void scheduleOperation(ServerOperation operation) { 632 void scheduleOperation(ServerOperation operation) {
641 addOperation(operation); 633 addOperation(operation);
642 if (!performOperationPending) { 634 if (!performOperationPending) {
643 _schedulePerformOperation(); 635 _schedulePerformOperation();
644 } 636 }
645 } 637 }
646 638
647 /** 639 /**
(...skipping 25 matching lines...) Expand all
673 } 665 }
674 666
675 /** 667 /**
676 * Send the given [response] to the client. 668 * Send the given [response] to the client.
677 */ 669 */
678 void sendResponse(Response response) { 670 void sendResponse(Response response) {
679 channel.sendResponse(response); 671 channel.sendResponse(response);
680 } 672 }
681 673
682 /** 674 /**
675 * Sends a `server.error` notification.
676 */
677 void sendServerErrorNotification(exception, stackTrace, {bool fatal: true}) {
Brian Wilkerson 2015/01/13 20:57:37 It looks like "false" is more common than "true".
scheglov 2015/01/13 21:13:51 Done.
678 // prepare exception.toString()
679 String exceptionString;
680 if (exception != null) {
681 exceptionString = exception.toString();
682 } else {
683 exceptionString = 'null exception';
684 }
685 // prepare stackTrace.toString()
686 String stackTraceString;
687 if (stackTrace != null) {
688 stackTraceString = stackTrace.toString();
689 } else {
690 stackTraceString = 'null stackTrace';
691 }
692 // send the notification
693 channel.sendNotification(
694 new ServerErrorParams(
695 fatal,
696 exceptionString,
697 stackTraceString).toNotification());
698 }
699
700 /**
683 * Send status notification to the client. The `operation` is the operation 701 * Send status notification to the client. The `operation` is the operation
684 * being performed or `null` if analysis is complete. 702 * being performed or `null` if analysis is complete.
685 */ 703 */
686 void sendStatusNotification(ServerOperation operation) { 704 void sendStatusNotification(ServerOperation operation) {
687 // Only send status when subscribed. 705 // Only send status when subscribed.
688 if (!serverServices.contains(ServerService.STATUS)) { 706 if (!serverServices.contains(ServerService.STATUS)) {
689 return; 707 return;
690 } 708 }
691 // Only send status when it changes 709 // Only send status when it changes
692 bool isAnalyzing = operation != null; 710 bool isAnalyzing = operation != null;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 } 926 }
909 927
910 /** 928 /**
911 * Schedules [performOperation] exection. 929 * Schedules [performOperation] exection.
912 */ 930 */
913 void _schedulePerformOperation() { 931 void _schedulePerformOperation() {
914 assert(!performOperationPending); 932 assert(!performOperationPending);
915 new Future(performOperation); 933 new Future(performOperation);
916 performOperationPending = true; 934 performOperationPending = true;
917 } 935 }
918
919 /**
920 * Sends a fatal `server.error` notification.
921 */
922 void _sendServerErrorNotification(exception, stackTrace) {
923 // prepare exception.toString()
924 String exceptionString;
925 if (exception != null) {
926 exceptionString = exception.toString();
927 } else {
928 exceptionString = 'null exception';
929 }
930 // prepare stackTrace.toString()
931 String stackTraceString;
932 if (stackTrace != null) {
933 stackTraceString = stackTrace.toString();
934 } else {
935 stackTraceString = 'null stackTrace';
936 }
937 // send the notification
938 channel.sendNotification(
939 new ServerErrorParams(
940 true,
941 exceptionString,
942 stackTraceString).toNotification());
943 }
944 } 936 }
945 937
946 938
947 class AnalysisServerOptions { 939 class AnalysisServerOptions {
948 bool enableIncrementalResolutionApi = false; 940 bool enableIncrementalResolutionApi = false;
949 bool enableIncrementalResolutionValidation = false; 941 bool enableIncrementalResolutionValidation = false;
950 } 942 }
951 943
952 /** 944 /**
953 * A [ContextsChangedEvent] indicate what contexts were added or removed. 945 * A [ContextsChangedEvent] indicate what contexts were added or removed.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 * [packageUriResolver]. 1071 * [packageUriResolver].
1080 */ 1072 */
1081 SourceFactory _createSourceFactory(UriResolver packageUriResolver) { 1073 SourceFactory _createSourceFactory(UriResolver packageUriResolver) {
1082 List<UriResolver> resolvers = <UriResolver>[ 1074 List<UriResolver> resolvers = <UriResolver>[
1083 new DartUriResolver(analysisServer.defaultSdk), 1075 new DartUriResolver(analysisServer.defaultSdk),
1084 new ResourceUriResolver(resourceProvider), 1076 new ResourceUriResolver(resourceProvider),
1085 packageUriResolver]; 1077 packageUriResolver];
1086 return new SourceFactory(resolvers); 1078 return new SourceFactory(resolvers);
1087 } 1079 }
1088 } 1080 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/operation/operation_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698