From 3027497f85cb5d5c21178e05966fc9ef7152aa8f Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 17 Nov 2015 23:23:30 -0800 Subject: [PATCH] Handle adb error cases more gracefully We now print a sensible message if we can't find `dart` or `adb`. Also, we print a sensible message if the device isn't authorized. Fixes #380 Fixes #358 --- bin/flutter | 6 ++++++ packages/flutter_tools/lib/src/device.dart | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/bin/flutter b/bin/flutter index adc85da197..5dabfb4d2d 100755 --- a/bin/flutter +++ b/bin/flutter @@ -3,6 +3,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +set -e + export FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}")) FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools" SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot" @@ -20,6 +22,8 @@ if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` echo -n $REVISION > "$STAMP_PATH" fi +set +e + $DART "$SNAPSHOT_PATH" "$@" # The VM exits with code 253 if the snapshot version is out-of-date. @@ -29,5 +33,7 @@ if [ $EXIT_CODE != 253 ]; then exit $EXIT_CODE fi +set -e + $DART --snapshot="$SNAPSHOT_PATH" --package-root="$FLUTTER_TOOLS_DIR/packages" "$SCRIPT_PATH" $DART "$SNAPSHOT_PATH" "$@" diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 5564b796f7..cf4df4167d 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -505,6 +505,14 @@ class AndroidDevice extends Device { static List getAttachedDevices([AndroidDevice mockAndroid]) { List devices = []; String adbPath = (mockAndroid != null) ? mockAndroid.adbPath : _getAdbPath(); + + try { + runCheckedSync([adbPath, 'version']); + } catch (e) { + _logging.severe('Unable to find adb. Is "adb" in your path?'); + return devices; + } + List output = runSync([adbPath, 'devices', '-l']).trim().split('\n'); // 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper @@ -514,6 +522,8 @@ class AndroidDevice extends Device { // 0149947A0D01500C device usb:340787200X RegExp deviceRegex2 = new RegExp(r'^(\S+)\s+device\s+\S+$'); + RegExp unauthorizedRegex = new RegExp(r'^(\S+)\s+unauthorized$'); + // Skip first line, which is always 'List of devices attached'. for (String line in output.skip(1)) { // Skip lines like: @@ -539,6 +549,13 @@ class AndroidDevice extends Device { Match match = deviceRegex2.firstMatch(line); String deviceID = match[1]; devices.add(new AndroidDevice(id: deviceID)); + } else if (unauthorizedRegex.hasMatch(line)) { + Match match = unauthorizedRegex.firstMatch(line); + String deviceID = match[1]; + _logging.warning( + 'Device $deviceID is not authorized.\n' + 'You might need to check your device for an authorization dialog.' + ); } else { _logging.warning( 'Unexpected failure parsing device information from adb output:\n'