handle any RPCError due to vm service disconnection in flutter run (#156346)

Follow-up to https://github.com/flutter/flutter/pull/153714. While reading through run.dart, I noticed we missed a case.
This commit is contained in:
Andrew Kolos 2024-10-07 11:48:22 -07:00 committed by GitHub
parent 9583cc1267
commit e96c47f953
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -856,7 +856,8 @@ class RunCommand extends RunCommandBase {
throwToolExit(null, exitCode: result);
}
} on RPCError catch (error) {
if (error.code == RPCErrorCodes.kServiceDisappeared) {
if (error.code == RPCErrorCodes.kServiceDisappeared ||
error.message.contains('Service connection disposed')) {
throwToolExit('Lost connection to device.');
}
rethrow;

View File

@ -1096,9 +1096,13 @@ void main() {
});
});
testUsingContext('Flutter run catches service has disappear errors and throws a tool exit', () async {
testUsingContext('Flutter run catches catches errors due to vm service disconnection and throws a tool exit', () async {
final FakeResidentRunner residentRunner = FakeResidentRunner();
residentRunner.rpcError = RPCError('flutter._listViews', RPCErrorCodes.kServiceDisappeared, '');
residentRunner.rpcError = RPCError(
'flutter._listViews',
RPCErrorCodes.kServiceDisappeared,
'',
);
final TestRunCommandWithFakeResidentRunner command = TestRunCommandWithFakeResidentRunner();
command.fakeResidentRunner = residentRunner;
@ -1106,6 +1110,17 @@ void main() {
'run',
'--no-pub',
]), contains('Lost connection to device.'));
residentRunner.rpcError = RPCError(
'flutter._listViews',
RPCErrorCodes.kServerError,
'Service connection disposed.',
);
await expectToolExitLater(createTestCommandRunner(command).run(<String>[
'run',
'--no-pub',
]), contains('Lost connection to device.'));
}, overrides: <Type, Generator>{
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),