diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bb5e3dfd43..ee1adaf96cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,15 @@ ### Language -* The identifier `async` can now be used in asynchronous and generator +* The identifier `async` can now be used in asynchronous and generator functions. -### Core library +### Core libraries + +#### `dart:developer` +* Exposed `result`, `errorCode` and `errorDetail` getters in + `ServiceExtensionResponse` to allow for better debugging of VM service + extension RPC results. #### `dart:io` diff --git a/runtime/lib/developer.dart b/runtime/lib/developer.dart index 12ad8b7c2e6..cb35073c137 100644 --- a/runtime/lib/developer.dart +++ b/runtime/lib/developer.dart @@ -131,7 +131,7 @@ _postResponse(SendPort replyPort, Object id, ServiceExtensionResponse response, assert(id != null); StringBuffer sb = new StringBuffer(); sb.write('{"jsonrpc":"2.0",'); - if (response._isError()) { + if (response.isError()) { if (trace_service) { print("vm-service: posting error response for request $id"); } diff --git a/sdk/lib/developer/extension.dart b/sdk/lib/developer/extension.dart index c6f4cce91b1..3cc4ede45ac 100644 --- a/sdk/lib/developer/extension.dart +++ b/sdk/lib/developer/extension.dart @@ -9,19 +9,24 @@ part of dart.developer; /// If the RPC was successful, use [ServiceExtensionResponse.result], otherwise /// use [ServiceExtensionResponse.error]. class ServiceExtensionResponse { - final String _result; - final int _errorCode; - final String _errorDetail; + /// The result of a successful service protocol extension RPC. + final String result; + + /// The error code associated with a failed service protocol extension RPC. + final int errorCode; + + /// The details of a failed service protocol extension RPC. + final String errorDetail; /// Creates a successful response to a service protocol extension RPC. /// /// Requires [result] to be a JSON object encoded as a string. When forming /// the JSON-RPC message [result] will be inlined directly. ServiceExtensionResponse.result(String result) - : _result = result, - _errorCode = null, - _errorDetail = null { - ArgumentError.checkNotNull(_result, "result"); + : result = result, + errorCode = null, + errorDetail = null { + ArgumentError.checkNotNull(result, "result"); } /// Creates an error response to a service protocol extension RPC. @@ -31,11 +36,11 @@ class ServiceExtensionResponse { /// encoded as a string. When forming the JSON-RPC message [errorDetail] will /// be inlined directly. ServiceExtensionResponse.error(int errorCode, String errorDetail) - : _result = null, - _errorCode = errorCode, - _errorDetail = errorDetail { - _validateErrorCode(_errorCode); - ArgumentError.checkNotNull(_errorDetail, "errorDetail"); + : result = null, + errorCode = errorCode, + errorDetail = errorDetail { + _validateErrorCode(errorCode); + ArgumentError.checkNotNull(errorDetail, "errorDetail"); } /// Invalid method parameter(s) error code. @@ -83,20 +88,20 @@ class ServiceExtensionResponse { throw new ArgumentError.value(errorCode, "errorCode", "Out of range"); } - // ignore: unused_element, called from runtime/lib/developer.dart - bool _isError() => (_errorCode != null) && (_errorDetail != null); + /// Determines if this response represents an error. + bool isError() => (errorCode != null) && (errorDetail != null); // ignore: unused_element, called from runtime/lib/developer.dart String _toString() { - if (_result != null) { - return _result; + if (result != null) { + return result; } else { - assert(_errorCode != null); - assert(_errorDetail != null); + assert(errorCode != null); + assert(errorDetail != null); return json.encode({ - 'code': _errorCode, - 'message': _errorCodeMessage(_errorCode), - 'data': {'details': _errorDetail} + 'code': errorCode, + 'message': _errorCodeMessage(errorCode), + 'data': {'details': errorDetail} }); } }