Skip to content

Commit e96c47f

Browse files
authored
handle any RPCError due to vm service disconnection in flutter run (#156346)
Follow-up to flutter/flutter#153714. While reading through run.dart, I noticed we missed a case.
1 parent 9583cc1 commit e96c47f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ class RunCommand extends RunCommandBase {
856856
throwToolExit(null, exitCode: result);
857857
}
858858
} on RPCError catch (error) {
859-
if (error.code == RPCErrorCodes.kServiceDisappeared) {
859+
if (error.code == RPCErrorCodes.kServiceDisappeared ||
860+
error.message.contains('Service connection disposed')) {
860861
throwToolExit('Lost connection to device.');
861862
}
862863
rethrow;

packages/flutter_tools/test/commands.shard/hermetic/run_test.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,16 +1096,31 @@ void main() {
10961096
});
10971097
});
10981098

1099-
testUsingContext('Flutter run catches service has disappear errors and throws a tool exit', () async {
1099+
testUsingContext('Flutter run catches catches errors due to vm service disconnection and throws a tool exit', () async {
11001100
final FakeResidentRunner residentRunner = FakeResidentRunner();
1101-
residentRunner.rpcError = RPCError('flutter._listViews', RPCErrorCodes.kServiceDisappeared, '');
1101+
residentRunner.rpcError = RPCError(
1102+
'flutter._listViews',
1103+
RPCErrorCodes.kServiceDisappeared,
1104+
'',
1105+
);
11021106
final TestRunCommandWithFakeResidentRunner command = TestRunCommandWithFakeResidentRunner();
11031107
command.fakeResidentRunner = residentRunner;
11041108

11051109
await expectToolExitLater(createTestCommandRunner(command).run(<String>[
11061110
'run',
11071111
'--no-pub',
11081112
]), contains('Lost connection to device.'));
1113+
1114+
residentRunner.rpcError = RPCError(
1115+
'flutter._listViews',
1116+
RPCErrorCodes.kServerError,
1117+
'Service connection disposed.',
1118+
);
1119+
1120+
await expectToolExitLater(createTestCommandRunner(command).run(<String>[
1121+
'run',
1122+
'--no-pub',
1123+
]), contains('Lost connection to device.'));
11091124
}, overrides: <Type, Generator>{
11101125
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
11111126
FileSystem: () => MemoryFileSystem.test(),

0 commit comments

Comments
 (0)