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

Unified Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 1246573002: Improve error messages for invalid requests (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/protocol.dart
diff --git a/pkg/analysis_server/lib/src/protocol.dart b/pkg/analysis_server/lib/src/protocol.dart
index f633eb8d7460738887d4b29067ea0e32c59a9ce4..aec8d718031308651d40461e4b09bdd8fd97c832 100644
--- a/pkg/analysis_server/lib/src/protocol.dart
+++ b/pkg/analysis_server/lib/src/protocol.dart
@@ -281,7 +281,7 @@ abstract class JsonDecoder {
* Create an exception to throw if the JSON object at [jsonPath] fails to
* match the API definition of [expected].
*/
- dynamic mismatch(String jsonPath, String expected);
+ dynamic mismatch(String jsonPath, String expected, [Object actual]);
/**
* Create an exception to throw if the JSON object at [jsonPath] is missing
@@ -301,7 +301,7 @@ abstract class JsonDecoder {
} else if (json == 'false') {
return false;
}
- throw mismatch(jsonPath, 'bool');
+ throw mismatch(jsonPath, 'bool', json);
}
/**
@@ -313,10 +313,10 @@ abstract class JsonDecoder {
return json;
} else if (json is String) {
return int.parse(json, onError: (String value) {
- throw mismatch(jsonPath, 'int');
+ throw mismatch(jsonPath, 'int', json);
});
}
- throw mismatch(jsonPath, 'int');
+ throw mismatch(jsonPath, 'int', json);
}
/**
@@ -334,7 +334,7 @@ abstract class JsonDecoder {
}
return result;
} else {
- throw mismatch(jsonPath, 'List');
+ throw mismatch(jsonPath, 'List', json);
}
}
@@ -362,7 +362,7 @@ abstract class JsonDecoder {
});
return result;
} else {
- throw mismatch(jsonPath, 'Map');
+ throw mismatch(jsonPath, 'Map', json);
}
}
@@ -373,7 +373,7 @@ abstract class JsonDecoder {
if (json is String) {
return json;
} else {
- throw mismatch(jsonPath, 'String');
+ throw mismatch(jsonPath, 'String', json);
}
}
@@ -392,11 +392,11 @@ abstract class JsonDecoder {
var disambiguatorPath = '$jsonPath[${JSON.encode(field)}]';
String disambiguator = _decodeString(disambiguatorPath, json[field]);
if (!decoders.containsKey(disambiguator)) {
- throw mismatch(disambiguatorPath, 'One of: ${decoders.keys.toList()}');
+ throw mismatch(disambiguatorPath, 'One of: ${decoders.keys.toList()}', json);
}
return decoders[disambiguator](jsonPath, json);
} else {
- throw mismatch(jsonPath, 'Map');
+ throw mismatch(jsonPath, 'Map', json);
}
}
}
@@ -616,9 +616,17 @@ class RequestDecoder extends JsonDecoder {
}
@override
- dynamic mismatch(String jsonPath, String expected) {
+ dynamic mismatch(String jsonPath, String expected, [Object actual]) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.write('Expected to be ');
+ buffer.write(expected);
+ if (actual != null) {
+ buffer.write('; found "');
+ buffer.write(JSON.encode(actual));
+ buffer.write('"');
+ }
return new RequestFailure(new Response.invalidParameter(
- _request, jsonPath, 'Expected to be $expected'));
+ _request, jsonPath, buffer.toString()));
}
@override
@@ -915,8 +923,18 @@ class ResponseDecoder extends JsonDecoder {
ResponseDecoder(this.refactoringKind);
@override
- dynamic mismatch(String jsonPath, String expected) {
- return new Exception('Expected $expected at $jsonPath');
+ dynamic mismatch(String jsonPath, String expected, [Object actual]) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.write('Expected ');
+ buffer.write(expected);
+ if (actual != null) {
+ buffer.write(' found "');
+ buffer.write(JSON.encode(actual));
+ buffer.write('"');
+ }
+ buffer.write(' at ');
+ buffer.write(jsonPath);
+ return new Exception(buffer.toString());
}
@override
« no previous file with comments | « pkg/analysis_server/lib/src/generated_protocol.dart ('k') | pkg/analysis_server/tool/spec/codegen_dart_protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698