Handle RPCError when VM service disappears while invoking VmService.getIsolate (#74528)

* Handle RPCError when VM service disappears while invoking `VmService.getIsolate`

* Add test
This commit is contained in:
Ben Konyi
2021-01-22 17:21:39 -08:00
committed by GitHub
parent 0d046b34ea
commit 35b9288e13
2 changed files with 21 additions and 1 deletions

View File

@@ -791,7 +791,10 @@ extension FlutterVmService on vm_service.VmService {
return getIsolate(isolateId)
.catchError((dynamic error, StackTrace stackTrace) {
return null;
}, test: (dynamic error) => error is vm_service.SentinelException);
}, test: (dynamic error) {
return (error is vm_service.SentinelException) ||
(error is vm_service.RPCError && error.code == RPCErrorCodes.kServiceDisappeared);
});
}
/// Create a new development file system on the device.

View File

@@ -333,6 +333,23 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
});
testWithoutContext('getIsolateOrNull returns null if service disappears ', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
const FakeVmServiceRequest(method: 'getIsolate', args: <String, Object>{
'isolateId': 'isolate/123',
}, errorCode: RPCErrorCodes.kServiceDisappeared),
]
);
final vm_service.Isolate isolate = await fakeVmServiceHost.vmService.getIsolateOrNull(
'isolate/123',
);
expect(isolate, null);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
});
testWithoutContext('getFlutterViews polls until a view is returned', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[