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

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

Issue 446983002: Change the type of Error.code from int to String. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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) 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 protocol; 5 library protocol;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' show JsonDecoder; 8 import 'dart:convert' show JsonDecoder;
9 9
10 import 'package:analysis_services/json.dart'; 10 import 'package:analysis_services/json.dart';
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 * with the given [id]. If an [error] is provided then the response will 506 * with the given [id]. If an [error] is provided then the response will
507 * represent an error condition. 507 * represent an error condition.
508 */ 508 */
509 Response(this.id, [this.error]); 509 Response(this.id, [this.error]);
510 510
511 /** 511 /**
512 * Initialize a newly created instance to represent an error condition caused 512 * Initialize a newly created instance to represent an error condition caused
513 * by a [request] referencing a context that does not exist. 513 * by a [request] referencing a context that does not exist.
514 */ 514 */
515 Response.contextDoesNotExist(Request request) 515 Response.contextDoesNotExist(Request request)
516 : this(request.id, new RequestError(-1, 'Context does not exist')); 516 : this(request.id, new RequestError('NONEXISTENT_CONTEXT', 'Context does not exist'));
517 517
518 /** 518 /**
519 * Initialize a newly created instance to represent an error condition caused 519 * Initialize a newly created instance to represent an error condition caused
520 * by a [request] that had invalid parameter. [path] is the path to the 520 * by a [request] that had invalid parameter. [path] is the path to the
521 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the 521 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the
522 * parameter "foo" contained a key "bar" whose value was the wrong type). 522 * parameter "foo" contained a key "bar" whose value was the wrong type).
523 * [expectation] is a description of the type of data that was expected. 523 * [expectation] is a description of the type of data that was expected.
524 */ 524 */
525 Response.invalidParameter(Request request, String path, String expectation) 525 Response.invalidParameter(Request request, String path, String expectation)
526 : this(request.id, new RequestError(-2, 526 : this(request.id, new RequestError('INVALID_PARAMETER',
527 "Expected parameter $path to $expectation")); 527 "Expected parameter $path to $expectation"));
528 528
529 /** 529 /**
530 * Initialize a newly created instance to represent an error condition caused 530 * Initialize a newly created instance to represent an error condition caused
531 * by a malformed request. 531 * by a malformed request.
532 */ 532 */
533 Response.invalidRequestFormat() 533 Response.invalidRequestFormat()
534 : this('', new RequestError(-4, 'Invalid request')); 534 : this('', new RequestError('INVALID_REQUEST', 'Invalid request'));
535 535
536 /** 536 /**
537 * Initialize a newly created instance to represent an error condition caused 537 * Initialize a newly created instance to represent an error condition caused
538 * by a [request] that does not have a required parameter. 538 * by a [request] that does not have a required parameter.
539 */ 539 */
540 Response.missingRequiredParameter(Request request, String parameterName) 540 Response.missingRequiredParameter(Request request, String parameterName)
541 : this(request.id, new RequestError(-5, 'Missing required parameter: $parame terName')); 541 : this(request.id, new RequestError('MISSING_PARAMETER', 'Missing required p arameter: $parameterName'));
542 542
543 /** 543 /**
544 * Initialize a newly created instance to represent an error condition caused 544 * Initialize a newly created instance to represent an error condition caused
545 * by a [request] that takes a set of analysis options but for which an 545 * by a [request] that takes a set of analysis options but for which an
546 * unknown analysis option was provided. 546 * unknown analysis option was provided.
547 */ 547 */
548 Response.unknownAnalysisOption(Request request, String optionName) 548 Response.unknownAnalysisOption(Request request, String optionName)
549 : this(request.id, new RequestError(-6, 'Unknown analysis option: "$optionNa me"')); 549 : this(request.id, new RequestError('UNKNOWN_ANALYSIS_OPTION', 'Unknown anal ysis option: "$optionName"'));
550 550
551 /** 551 /**
552 * Initialize a newly created instance to represent an error condition caused 552 * Initialize a newly created instance to represent an error condition caused
553 * by a [request] that cannot be handled by any known handlers. 553 * by a [request] that cannot be handled by any known handlers.
554 */ 554 */
555 Response.unknownRequest(Request request) 555 Response.unknownRequest(Request request)
556 : this(request.id, new RequestError(-7, 'Unknown request')); 556 : this(request.id, new RequestError('UNKNOWN_REQUEST', 'Unknown request'));
557 557
558 Response.contextAlreadyExists(Request request) 558 Response.contextAlreadyExists(Request request)
559 : this(request.id, new RequestError(-8, 'Context already exists')); 559 : this(request.id, new RequestError('CONTENT_ALREADY_EXISTS', 'Context alrea dy exists'));
560 560
561 Response.unsupportedFeature(String requestId, String message) 561 Response.unsupportedFeature(String requestId, String message)
562 : this(requestId, new RequestError(-9, message)); 562 : this(requestId, new RequestError('UNSUPPORTED_FEATURE', message));
563 563
564 /** 564 /**
565 * Initialize a newly created instance to represent an error condition caused 565 * Initialize a newly created instance to represent an error condition caused
566 * by a `analysis.setSubscriptions` [request] that includes an unknown 566 * by a `analysis.setSubscriptions` [request] that includes an unknown
567 * analysis service name. 567 * analysis service name.
568 */ 568 */
569 Response.unknownAnalysisService(Request request, String name) 569 Response.unknownAnalysisService(Request request, String name)
570 : this(request.id, new RequestError(-10, 'Unknown analysis service: "$name"' )); 570 : this(request.id, new RequestError('UNKNOWN_ANALYSIS_SERVICE', 'Unknown ana lysis service: "$name"'));
571 571
572 /** 572 /**
573 * Initialize a newly created instance to represent an error condition caused 573 * Initialize a newly created instance to represent an error condition caused
574 * by a `analysis.setPriorityFiles` [request] that includes one or more files 574 * by a `analysis.setPriorityFiles` [request] that includes one or more files
575 * that are not being analyzed. 575 * that are not being analyzed.
576 */ 576 */
577 Response.unanalyzedPriorityFiles(Request request, String fileNames) 577 Response.unanalyzedPriorityFiles(Request request, String fileNames)
578 : this(request.id, new RequestError(-11, "Unanalyzed files cannot be a prior ity: '$fileNames'")); 578 : this(request.id, new RequestError('UNANALYZED_PRIORITY_FILES', "Unanalyzed files cannot be a priority: '$fileNames'"));
579 579
580 /** 580 /**
581 * Initialize a newly created instance to represent an error condition caused 581 * Initialize a newly created instance to represent an error condition caused
582 * by a `analysis.updateOptions` [request] that includes an unknown analysis 582 * by a `analysis.updateOptions` [request] that includes an unknown analysis
583 * option. 583 * option.
584 */ 584 */
585 Response.unknownOptionName(Request request, String optionName) 585 Response.unknownOptionName(Request request, String optionName)
586 : this(request.id, new RequestError(-12, 'Unknown analysis option: "$optionN ame"')); 586 : this(request.id, new RequestError('UNKNOWN_OPTION_NAME', 'Unknown analysis option: "$optionName"'));
587 587
588 /** 588 /**
589 * Initialize a newly created instance to represent an error condition caused 589 * Initialize a newly created instance to represent an error condition caused
590 * by an error during `analysis.getErrors`. 590 * by an error during `analysis.getErrors`.
591 */ 591 */
592 Response.getErrorsError(Request request, String message) 592 Response.getErrorsError(Request request, String message)
593 : this( 593 : this(
594 request.id, 594 request.id,
595 new RequestError(-13, 'Error during `analysis.getErrors`: $message.')); 595 new RequestError('GET_ERRORS_ERROR', 'Error during `analysis.getErrors`: $message.'));
596 596
597 /** 597 /**
598 * Initialize a newly created instance based upon the given JSON data 598 * Initialize a newly created instance based upon the given JSON data
599 */ 599 */
600 factory Response.fromJson(Map<String, Object> json) { 600 factory Response.fromJson(Map<String, Object> json) {
601 try { 601 try {
602 Object id = json[Response.ID]; 602 Object id = json[Response.ID];
603 if (id is! String) { 603 if (id is! String) {
604 return null; 604 return null;
605 } 605 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 672
673 /** 673 /**
674 * The name of the JSON attribute containing a short description of the error. 674 * The name of the JSON attribute containing a short description of the error.
675 */ 675 */
676 static const String MESSAGE = 'message'; 676 static const String MESSAGE = 'message';
677 677
678 /** 678 /**
679 * An error code indicating a parse error. Invalid JSON was received by the 679 * An error code indicating a parse error. Invalid JSON was received by the
680 * server. An error occurred on the server while parsing the JSON text. 680 * server. An error occurred on the server while parsing the JSON text.
681 */ 681 */
682 static const int CODE_PARSE_ERROR = -32700; 682 static const String CODE_PARSE_ERROR = 'PARSE_ERROR';
683 683
684 /** 684 /**
685 * An error code indicating that the analysis server has already been 685 * An error code indicating that the analysis server has already been
686 * started (and hence won't accept new connections). 686 * started (and hence won't accept new connections).
687 */ 687 */
688 static const int CODE_SERVER_ALREADY_STARTED = -32701; 688 static const String CODE_SERVER_ALREADY_STARTED = 'SERVER_ALREADY_STARTED';
689 689
690 /** 690 /**
691 * An error code indicating an invalid request. The JSON sent is not a valid 691 * An error code indicating an invalid request. The JSON sent is not a valid
692 * [Request] object. 692 * [Request] object.
693 */ 693 */
694 static const int CODE_INVALID_REQUEST = -32600; 694 static const String CODE_INVALID_REQUEST = 'INVALID_REQUEST';
695 695
696 /** 696 /**
697 * An error code indicating a method not found. The method does not exist or 697 * An error code indicating a method not found. The method does not exist or
698 * is not currently available. 698 * is not currently available.
699 */ 699 */
700 static const int CODE_METHOD_NOT_FOUND = -32601; 700 static const String CODE_METHOD_NOT_FOUND = 'METHOD_NOT_FOUND';
701 701
702 /** 702 /**
703 * An error code indicating one or more invalid parameters. 703 * An error code indicating one or more invalid parameters.
704 */ 704 */
705 static const int CODE_INVALID_PARAMS = -32602; 705 static const String CODE_INVALID_PARAMS = 'INVALID_PARAMS';
706 706
707 /** 707 /**
708 * An error code indicating an internal error. 708 * An error code indicating an internal error.
709 */ 709 */
710 static const int CODE_INTERNAL_ERROR = -32603; 710 static const String CODE_INTERNAL_ERROR = 'INTERNAL_ERROR';
711 711
712 /** 712 /**
713 * An error code indicating a problem using the specified Dart SDK. 713 * An error code indicating a problem using the specified Dart SDK.
714 */ 714 */
715 static const int CODE_SDK_ERROR = -32603; 715 static const String CODE_SDK_ERROR = 'SDK_ERROR';
716 716
717 /** 717 /**
718 * An error code indicating a problem during 'analysis.getErrors'. 718 * An error code indicating a problem during 'analysis.getErrors'.
719 */ 719 */
720 static const int CODE_ANALISYS_GET_ERRORS_ERROR = -32500; 720 static const String CODE_ANALISYS_GET_ERRORS_ERROR = 'ANALYSIS_GET_ERRORS_ERRO R';
721
722 /*
723 * In addition, codes -32000 to -32099 indicate a server error. They are
724 * reserved for implementation-defined server-errors.
725 */
726 721
727 /** 722 /**
728 * The code that uniquely identifies the error that occurred. 723 * The code that uniquely identifies the error that occurred.
729 */ 724 */
730 final int code; 725 final String code;
731 726
732 /** 727 /**
733 * A short description of the error. 728 * A short description of the error.
734 */ 729 */
735 final String message; 730 final String message;
736 731
737 /** 732 /**
738 * A table mapping the names of notification parameters to their values. 733 * A table mapping the names of notification parameters to their values.
739 */ 734 */
740 final Map<String, Object> data = new HashMap<String, Object>(); 735 final Map<String, Object> data = new HashMap<String, Object>();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 /** 774 /**
780 * Initialize a newly created [Error] to indicate an internal error. 775 * Initialize a newly created [Error] to indicate an internal error.
781 */ 776 */
782 RequestError.internalError() : this(CODE_INTERNAL_ERROR, "Internal error"); 777 RequestError.internalError() : this(CODE_INTERNAL_ERROR, "Internal error");
783 778
784 /** 779 /**
785 * Initialize a newly created [Error] from the given JSON. 780 * Initialize a newly created [Error] from the given JSON.
786 */ 781 */
787 factory RequestError.fromJson(Map<String, Object> json) { 782 factory RequestError.fromJson(Map<String, Object> json) {
788 try { 783 try {
789 int code = json[RequestError.CODE]; 784 String code = json[RequestError.CODE];
790 String message = json[RequestError.MESSAGE]; 785 String message = json[RequestError.MESSAGE];
791 Map<String, Object> data = json[RequestError.DATA]; 786 Map<String, Object> data = json[RequestError.DATA];
792 RequestError requestError = new RequestError(code, message); 787 RequestError requestError = new RequestError(code, message);
793 if (data != null) { 788 if (data != null) {
794 data.forEach((String key, Object value) { 789 data.forEach((String key, Object value) {
795 requestError.setData(key, value); 790 requestError.setData(key, value);
796 }); 791 });
797 } 792 }
798 return requestError; 793 return requestError;
799 } catch (exception) { 794 } catch (exception) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 */ 940 */
946 _toJson(Object value) { 941 _toJson(Object value) {
947 if (value is HasToJson) { 942 if (value is HasToJson) {
948 return value.toJson(); 943 return value.toJson();
949 } 944 }
950 if (value is Iterable) { 945 if (value is Iterable) {
951 return value.map((item) => _toJson(item)).toList(); 946 return value.map((item) => _toJson(item)).toList();
952 } 947 }
953 return value; 948 return value;
954 } 949 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/test/analysis/get_errors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698