Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cca2bb3

Browse files
committed
[ dart:developer ] Exposed reason, errorCode, and errorDetail getters in ServiceExtensionResult.
Fixes issue #36163. Change-Id: I33b8324e9c16fb12e80dd91beb275320b64f7316 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103462 Reviewed-by: Ryan Macnak <[email protected]>
1 parent 03781b9 commit cca2bb3

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44

55
### Language
66

7-
* The identifier `async` can now be used in asynchronous and generator
7+
* The identifier `async` can now be used in asynchronous and generator
88
functions.
99

10-
### Core library
10+
### Core libraries
11+
12+
#### `dart:developer`
13+
* Exposed `result`, `errorCode` and `errorDetail` getters in
14+
`ServiceExtensionResponse` to allow for better debugging of VM service
15+
extension RPC results.
1116

1217
#### `dart:io`
1318

runtime/lib/developer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ _postResponse(SendPort replyPort, Object id, ServiceExtensionResponse response,
131131
assert(id != null);
132132
StringBuffer sb = new StringBuffer();
133133
sb.write('{"jsonrpc":"2.0",');
134-
if (response._isError()) {
134+
if (response.isError()) {
135135
if (trace_service) {
136136
print("vm-service: posting error response for request $id");
137137
}

sdk/lib/developer/extension.dart

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ part of dart.developer;
99
/// If the RPC was successful, use [ServiceExtensionResponse.result], otherwise
1010
/// use [ServiceExtensionResponse.error].
1111
class ServiceExtensionResponse {
12-
final String _result;
13-
final int _errorCode;
14-
final String _errorDetail;
12+
/// The result of a successful service protocol extension RPC.
13+
final String result;
14+
15+
/// The error code associated with a failed service protocol extension RPC.
16+
final int errorCode;
17+
18+
/// The details of a failed service protocol extension RPC.
19+
final String errorDetail;
1520

1621
/// Creates a successful response to a service protocol extension RPC.
1722
///
1823
/// Requires [result] to be a JSON object encoded as a string. When forming
1924
/// the JSON-RPC message [result] will be inlined directly.
2025
ServiceExtensionResponse.result(String result)
21-
: _result = result,
22-
_errorCode = null,
23-
_errorDetail = null {
24-
ArgumentError.checkNotNull(_result, "result");
26+
: result = result,
27+
errorCode = null,
28+
errorDetail = null {
29+
ArgumentError.checkNotNull(result, "result");
2530
}
2631

2732
/// Creates an error response to a service protocol extension RPC.
@@ -31,11 +36,11 @@ class ServiceExtensionResponse {
3136
/// encoded as a string. When forming the JSON-RPC message [errorDetail] will
3237
/// be inlined directly.
3338
ServiceExtensionResponse.error(int errorCode, String errorDetail)
34-
: _result = null,
35-
_errorCode = errorCode,
36-
_errorDetail = errorDetail {
37-
_validateErrorCode(_errorCode);
38-
ArgumentError.checkNotNull(_errorDetail, "errorDetail");
39+
: result = null,
40+
errorCode = errorCode,
41+
errorDetail = errorDetail {
42+
_validateErrorCode(errorCode);
43+
ArgumentError.checkNotNull(errorDetail, "errorDetail");
3944
}
4045

4146
/// Invalid method parameter(s) error code.
@@ -83,20 +88,20 @@ class ServiceExtensionResponse {
8388
throw new ArgumentError.value(errorCode, "errorCode", "Out of range");
8489
}
8590

86-
// ignore: unused_element, called from runtime/lib/developer.dart
87-
bool _isError() => (_errorCode != null) && (_errorDetail != null);
91+
/// Determines if this response represents an error.
92+
bool isError() => (errorCode != null) && (errorDetail != null);
8893

8994
// ignore: unused_element, called from runtime/lib/developer.dart
9095
String _toString() {
91-
if (_result != null) {
92-
return _result;
96+
if (result != null) {
97+
return result;
9398
} else {
94-
assert(_errorCode != null);
95-
assert(_errorDetail != null);
99+
assert(errorCode != null);
100+
assert(errorDetail != null);
96101
return json.encode({
97-
'code': _errorCode,
98-
'message': _errorCodeMessage(_errorCode),
99-
'data': {'details': _errorDetail}
102+
'code': errorCode,
103+
'message': _errorCodeMessage(errorCode),
104+
'data': {'details': errorDetail}
100105
});
101106
}
102107
}

0 commit comments

Comments
 (0)