From ff84b3e66dc4f3c265b381d7d8c640343ec4902d Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Mon, 18 Nov 2019 13:53:55 -0800 Subject: [PATCH] catch IOSDeviceNotFoundError in IOSDevice.startApp() (#45011) --- packages/flutter_tools/lib/src/ios/devices.dart | 10 +++++++++- .../test/general.shard/ios/devices_test.dart | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index bb481a581a..b70ff9d4e3 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -282,7 +282,15 @@ class IOSDevice extends Device { // TODO(chinmaygarde): Use mainPath, route. printTrace('Building ${package.name} for $id'); - final String cpuArchitecture = await iMobileDevice.getInfoForDevice(id, 'CPUArchitecture'); + String cpuArchitecture; + + try { + cpuArchitecture = await iMobileDevice.getInfoForDevice(id, 'CPUArchitecture'); + } on IOSDeviceNotFoundError catch (e) { + printError(e.message); + return LaunchResult.failed(); + } + final DarwinArch iosArch = getIOSArchForName(cpuArchitecture); // Step 1: Build the precompiled/DBC application if necessary. diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart index 56d7b72733..20f48c61cb 100644 --- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart @@ -249,6 +249,22 @@ void main() { Cache.enableLocking(); }); + testUsingContext('returns failed if the IOSDevice is not found', () async { + final IOSDevice device = IOSDevice('123'); + when(mockIMobileDevice.getInfoForDevice(any, 'CPUArchitecture')).thenThrow( + const IOSDeviceNotFoundError( + 'ideviceinfo could not find device:\n' + 'No device found with udid 123, is it plugged in?\n' + 'Try unlocking attached devices.' + ) + ); + final LaunchResult result = await device.startApp(mockApp); + expect(result.started, false); + }, overrides: { + IMobileDevice: () => mockIMobileDevice, + Platform: () => macPlatform, + }); + testUsingContext(' succeeds in debug mode via mDNS', () async { final IOSDevice device = IOSDevice('123'); device.portForwarder = mockPortForwarder;