-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
It appears that VMService no longer supports a null 'type' in a response message when running with sound null safety.
For example if we have the following registered in a VM instance:
registerExtension('ext.cocoonRunnerReady',
(String method, Map<String, String> parameters) async {
return ServiceExtensionResponse.result('"ready"');
});And when trying to call this extension from outside the VM with VMService:
final Response response = await client.callServiceExtension('ext.cocoonRunnerReady', isolateId: isolate.id);Where client is a VMService it will crash with:
type 'Null' is not a subtype of type 'String'
#0 VmService._processResponse (package:vm_service/src/vm_service.dart:2195:14)
#1 VmService._processMessageStr (package:vm_service/src/vm_service.dart:2181:7)
#2 VmService._processMessage (package:vm_service/src/vm_service.dart:2133:7)
Looking at the code, it looks like this is the problem:
String type = result['type'];
if (type == 'Sentinel') {
request.completeError(SentinelException.parse(request.method, result));
} else if (_typeFactories[type] == null) {
request.complete(Response.parse(result));
} else {
List<String> returnTypes = _methodReturnTypes[request.method] ?? [];
request.complete(createServiceObject(result, returnTypes));
}If this is run without null safety, it will be ok for type to be null and it will fall through to the first else clause and return a response parsed from the result. However, with null safety turned on it will crash.
This is blocking the Flutter team from migrating all of our devicelab tests over to null safety. If I update my local copy of this to:
String? type = result['type'];everything seems to work fine for us again.
- Dart SDK version: 2.14.0-271.0.dev
- vm_service: 7.1.0
- This was tested on MacOS if that is important
Let me know if you need more information.