Commit 8df5e9f7 authored by Adam Barth's avatar Adam Barth

Polish up some error handling

This patch improves the error handling for several arbitrary issues I
encountered while experimenting with the tool this evening.
parent bdd20661
......@@ -10,7 +10,7 @@ import 'flutter_command.dart';
class InstallCommand extends FlutterCommand {
final String name = 'install';
final String description = 'Install your Flutter app on attached devices.';
final String description = 'Install Flutter apps on attached devices.';
InstallCommand() {
argParser.addFlag('boot',
......@@ -31,7 +31,7 @@ class InstallCommand extends FlutterCommand {
for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null || !device.isConnected())
if (package == null || !device.isConnected() || device.isAppInstalled(package))
continue;
if (device.installApp(package))
installedSomewhere = true;
......
......@@ -22,7 +22,16 @@ class ListenCommand extends FlutterCommand {
/// Only run once. Used for testing.
bool singleRun;
ListenCommand({ this.singleRun: false });
ListenCommand({ this.singleRun: false }) {
argParser.addFlag('checked',
negatable: true,
defaultsTo: true,
help: 'Toggle Dart\'s checked mode.');
argParser.addOption('target',
defaultsTo: '.',
abbr: 't',
help: 'Target app path or filename to start.');
}
@override
Future<int> run() async {
......
......@@ -142,10 +142,15 @@ class IOSDevice extends Device {
static Iterable<String> _getAttachedDeviceIDs([IOSDevice mockIOS]) {
String listerPath =
(mockIOS != null) ? mockIOS.listerPath : _checkForCommand('idevice_id');
return runSync([listerPath, '-l'])
.trim()
.split('\n')
.where((String s) => s != null && s.length > 0);
String output;
try {
output = runSync([listerPath, '-l']);
} catch (e) {
return [];
}
return output.trim()
.split('\n')
.where((String s) => s != null && s.length > 0);
}
static String _getDeviceName(String deviceID, [IOSDevice mockIOS]) {
......@@ -805,6 +810,10 @@ class AndroidDevice extends Device {
// Kill the server
if (Platform.isMacOS) {
String pid = runSync(['lsof', '-i', ':$_serverPort', '-t']);
if (pid.isEmpty) {
_logging.fine('No process to kill for port $_serverPort');
return true;
}
// Killing a pid with a shell command from within dart is hard,
// so use a library command, but it's still nice to give the
// equivalent command when doing verbose logging.
......
......@@ -19,12 +19,15 @@ defineTests() {
MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(true);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(true);
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
......@@ -39,12 +42,15 @@ defineTests() {
MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(false);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(false);
when(mockDevices.iOS.isConnected()).thenReturn(true);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(true);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
CommandRunner runner = new CommandRunner('test_flutter', '')
......
......@@ -19,16 +19,19 @@ defineTests() {
MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(true);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(true);
when(mockDevices.android.startServer(any, any, any, any)).thenReturn(true);
when(mockDevices.android.stopApp(any)).thenReturn(true);
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(false);
when(mockDevices.iOS.startApp(any)).thenReturn(false);
when(mockDevices.iOS.stopApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.startApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
......@@ -44,16 +47,19 @@ defineTests() {
MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(false);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(false);
when(mockDevices.android.startServer(any, any, any, any)).thenReturn(false);
when(mockDevices.android.stopApp(any)).thenReturn(false);
when(mockDevices.iOS.isConnected()).thenReturn(true);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(true);
when(mockDevices.iOS.startApp(any)).thenReturn(true);
when(mockDevices.iOS.stopApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.startApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
......
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