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:
@@ -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.
|
||||
|
||||
@@ -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>[
|
||||
|
||||
Reference in New Issue
Block a user