catch IOSDeviceNotFoundError in IOSDevice.startApp() (#45011)

This commit is contained in:
Christopher Fujino
2019-11-18 13:53:55 -08:00
committed by GitHub
parent 01b0a62974
commit ff84b3e66d
2 changed files with 25 additions and 1 deletions

View File

@@ -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.

View File

@@ -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: <Type, Generator>{
IMobileDevice: () => mockIMobileDevice,
Platform: () => macPlatform,
});
testUsingContext(' succeeds in debug mode via mDNS', () async {
final IOSDevice device = IOSDevice('123');
device.portForwarder = mockPortForwarder;