Unverified Commit 8930e9b8 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Catch FormatException parsing XCDevice._getAllDevices (#90967)

parent b1126d87
...@@ -112,9 +112,16 @@ class XCDevice { ...@@ -112,9 +112,16 @@ class XCDevice {
throwOnError: true, throwOnError: true,
); );
if (result.exitCode == 0) { if (result.exitCode == 0) {
final List<dynamic> listResults = json.decode(result.stdout) as List<dynamic>; final String listOutput = result.stdout;
_cachedListResults = listResults; try {
return listResults; final List<dynamic> listResults = json.decode(listOutput) as List<dynamic>;
_cachedListResults = listResults;
return listResults;
} on FormatException {
// xcdevice logs errors and crashes to stdout.
_logger.printError('xcdevice returned non-JSON response: $listOutput');
return null;
}
} }
_logger.printTrace('xcdevice returned an error:\n${result.stderr}'); _logger.printTrace('xcdevice returned an error:\n${result.stderr}');
} on ProcessException catch (exception) { } on ProcessException catch (exception) {
......
...@@ -680,6 +680,19 @@ void main() { ...@@ -680,6 +680,19 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => macPlatform, Platform: () => macPlatform,
}); });
testUsingContext('handles bad output',() async {
fakeProcessManager.addCommand(const FakeCommand(
command: <String>['xcrun', 'xcdevice', 'list', '--timeout', '2'],
stdout: 'Something bad happened, not JSON',
));
final List<IOSDevice> devices = await xcdevice.getAvailableIOSDevices();
expect(devices, isEmpty);
expect(logger.errorText, contains('xcdevice returned non-JSON response'));
}, overrides: <Type, Generator>{
Platform: () => macPlatform,
});
}); });
group('diagnostics', () { group('diagnostics', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment