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

Unified Diff: runtime/bin/vmservice/client/lib/src/service/object.dart

Issue 274603003: Potential workaround for JSON decode errors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/vmservice/client/deployed/web/index_devtools.html_bootstrap.dart.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/client/lib/src/service/object.dart
diff --git a/runtime/bin/vmservice/client/lib/src/service/object.dart b/runtime/bin/vmservice/client/lib/src/service/object.dart
index a94a70673f95977f89fe71b4b496fa751a092262..0a8e54dbdbc815fe7b90e0243658092353457c24 100644
--- a/runtime/bin/vmservice/client/lib/src/service/object.dart
+++ b/runtime/bin/vmservice/client/lib/src/service/object.dart
@@ -284,6 +284,21 @@ abstract class VM extends ServiceObjectOwner {
});
}
+ dynamic _reviver(dynamic key, dynamic value) {
+ return value;
+ }
+
+ ObservableMap _parseJSON(String response) {
+ var map;
+ try {
+ var decoder = new JsonDecoder(_reviver);
+ map = decoder.convert(response);
+ } catch (e, st) {
+ return null;
+ }
+ return toObservable(map);
+ }
+
Future<ObservableMap> _processMap(ObservableMap map) {
// Verify that the top level response is a service map.
if (!_isServiceMap(map)) {
@@ -306,30 +321,35 @@ abstract class VM extends ServiceObjectOwner {
return new Future.value(map);
}
+ Future<ObservableMap> _decodeError(e) {
+ return new Future.error(new ServiceObject._fromMap(this, toObservable({
+ 'type': 'ServiceException',
+ 'id': '',
+ 'kind': 'DecodeException',
+ 'response':
+ 'This is likely a result of a known V8 bug. Although the '
+ 'the bug has been fixed the fix may not be in your Chrome'
+ ' version. For more information see dartbug.com/18385. '
+ 'Observatory is still functioning and you should try your'
+ ' action again.',
+ 'message': 'Could not decode JSON: $e',
+ })));
+ }
+
/// Gets [id] as an [ObservableMap] from the service directly. If
/// an error occurs, the future is completed as an error with a
/// ServiceError or ServiceException. Therefore any chained then() calls
/// will only receive a map encoding a valid ServiceObject.
Future<ObservableMap> getAsMap(String id) {
return getString(id).then((response) {
+ var map;
try {
- var map = toObservable(JSON.decode(response));
- return _processMap(map);
+ map = _parseJSON(response);
} catch (e, st) {
- return new Future.error(
- new ServiceObject._fromMap(this, toObservable({
- 'type': 'ServiceException',
- 'id': '',
- 'kind': 'DecodeException',
- 'response':
- 'This is likely a result of a known V8 bug. Although the '
- 'the bug has been fixed the fix may not be in your Chrome'
- ' version. For more information see dartbug.com/18385. '
- 'Observatory is still functioning and you should try your'
- ' action again.',
- 'message': 'Could not decode JSON: $e',
- })));
+ print('Hit V8 bug.');
+ return _decodeError(e);
}
+ return _processMap(map);
}).catchError((error) {
// ServiceError, forward to VM's ServiceError stream.
errors.add(error);
« no previous file with comments | « runtime/bin/vmservice/client/deployed/web/index_devtools.html_bootstrap.dart.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698