Skip to content

Commit 5cb2dcf

Browse files
authored
Use new error codes from package:vm_service (#2141)
1 parent 81ae77a commit 5cb2dcf

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

dwds/lib/src/debugging/debugger.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Debugger extends Domain {
158158
if (stackComputer == null) {
159159
throw RPCError(
160160
'getStack',
161-
RPCError.kInternalError,
161+
RPCErrorKind.kInternalError.code,
162162
'Cannot compute stack when application is not paused',
163163
);
164164
}
@@ -323,7 +323,7 @@ class Debugger extends Domain {
323323
if (jsId == null) {
324324
throw RPCError(
325325
'removeBreakpoint',
326-
RPCError.kInternalError,
326+
RPCErrorKind.kInternalError.code,
327327
'invalid JS breakpoint id $jsId',
328328
);
329329
}
@@ -715,7 +715,7 @@ Future<T> sendCommandAndValidateResult<T>(
715715
if (result == null) {
716716
throw RPCError(
717717
method,
718-
RPCError.kInternalError,
718+
RPCErrorKind.kInternalError.code,
719719
'$resultField not found in result from sendCommand',
720720
params,
721721
);

dwds/lib/src/debugging/inspector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class AppInspector implements AppInspectorInterface {
448448
if (result == null) {
449449
throw RPCError(
450450
'getMemoryUsage',
451-
RPCError.kInternalError,
451+
RPCErrorKind.kInternalError.code,
452452
'Null result from chrome Devtools.',
453453
);
454454
}
@@ -461,7 +461,7 @@ class AppInspector implements AppInspectorInterface {
461461
if (usage == null) {
462462
throw RPCError(
463463
'getMemoryUsage',
464-
RPCError.kInternalError,
464+
RPCErrorKind.kInternalError.code,
465465
'Failed to parse memory usage result.',
466466
);
467467
}

dwds/lib/src/dwds_vm_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class DwdsVmClient {
142142
if (ddsUri == null) {
143143
return RPCError(
144144
request['method'] as String,
145-
RPCError.kInvalidParams,
145+
RPCErrorKind.kInvalidParams.code,
146146
"'Missing parameter: 'uri'",
147147
).toMap();
148148
}
@@ -229,7 +229,7 @@ Future<Map<String, dynamic>> _hotRestart(
229229
// triggered in the middle of a full reload.
230230
return {
231231
'error': {
232-
'code': RPCError.kInternalError,
232+
'code': RPCErrorKind.kInternalError.code,
233233
'message': e.message,
234234
}
235235
};
@@ -249,7 +249,7 @@ Future<Map<String, dynamic>> _hotRestart(
249249
final message = exception.error?['message'];
250250
// This corresponds to `Execution context was destroyed` which can
251251
// occur during a hot restart that must fall back to a full reload.
252-
if (code != RPCError.kServerError) {
252+
if (code != RPCErrorKind.kServerError.code) {
253253
return {
254254
'error': {
255255
'code': code,
@@ -262,7 +262,7 @@ Future<Map<String, dynamic>> _hotRestart(
262262
// Exceptions thrown by the injected client during hot restart.
263263
return {
264264
'error': {
265-
'code': RPCError.kInternalError,
265+
'code': RPCErrorKind.kInternalError.code,
266266
'message': '$exception',
267267
}
268268
};

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
563563
}
564564
throw RPCError(
565565
'evaluateInFrame',
566-
RPCError.kInvalidRequest,
566+
RPCErrorKind.kInvalidRequest.code,
567567
'Expression evaluation is not supported for this configuration.',
568568
);
569569
},
@@ -602,7 +602,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
602602
}
603603
throw RPCError(
604604
'evaluateInFrame',
605-
RPCError.kInvalidRequest,
605+
RPCErrorKind.kInvalidRequest.code,
606606
'Expression evaluation is not supported for this configuration.',
607607
);
608608
},
@@ -811,7 +811,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
811811
default:
812812
throw RPCError(
813813
'streamListen',
814-
RPCError.kInvalidParams,
814+
RPCErrorKind.kInvalidParams.code,
815815
'The stream `$streamId` is not supported on web devices',
816816
);
817817
}
@@ -861,7 +861,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
861861
return Future.error(
862862
RPCError(
863863
'reloadSources',
864-
RPCError.kMethodNotFound,
864+
RPCErrorKind.kMethodNotFound.code,
865865
'Hot reload not supported on web devices',
866866
),
867867
);
@@ -905,10 +905,11 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
905905
final errorMessage = e.message;
906906
if (errorMessage != null &&
907907
errorMessage.contains('Can only perform operation while paused')) {
908-
// TODO(https://github.com/dart-lang/sdk/issues/52636): Use error code
909-
// from package:vm_service.
910-
const kIsolateMustBePausedCode = 106;
911-
throw RPCError('resume', kIsolateMustBePausedCode, errorMessage);
908+
throw RPCError(
909+
'resume',
910+
RPCErrorKind.kIsolateMustBePaused.code,
911+
errorMessage,
912+
);
912913
}
913914
rethrow;
914915
}
@@ -1267,7 +1268,7 @@ ${globalLoadStrategy.loadModuleSnippet}("dart_sdk").developer.invokeExtension(
12671268
static RPCError _rpcNotSupported(String method) {
12681269
return RPCError(
12691270
method,
1270-
RPCError.kMethodNotFound,
1271+
RPCErrorKind.kMethodNotFound.code,
12711272
'$method: Not supported on web devices',
12721273
);
12731274
}

dwds/lib/src/utilities/domain.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,5 @@ abstract class Domain {
136136
}
137137

138138
Never throwInvalidParam(String method, String message) {
139-
throw RPCError(method, RPCError.kInvalidParams, message);
139+
throw RPCError(method, RPCErrorKind.kInvalidParams.code, message);
140140
}

dwds/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies:
3333
stack_trace: ^1.10.0
3434
sse: ^4.1.2
3535
uuid: ^3.0.6
36-
vm_service: ">=10.1.2 <12.0.0"
36+
vm_service: ^11.7.1
3737
web_socket_channel: ^2.2.0
3838
webkit_inspection_protocol: ^1.0.1
3939

dwds/test/chrome_proxy_service_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,8 @@ void main() {
23822382
() => service.streamListen('aCustomStreamId'),
23832383
throwsA(
23842384
predicate(
2385-
(e) => (e is RPCError) && e.code == RPCError.kInvalidParams,
2385+
(e) =>
2386+
(e is RPCError) && e.code == RPCErrorKind.kInvalidParams.code,
23862387
),
23872388
),
23882389
);

0 commit comments

Comments
 (0)