diff options
Diffstat (limited to 'catapult/devil/devil/android/device_errors.py')
-rw-r--r-- | catapult/devil/devil/android/device_errors.py | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/catapult/devil/devil/android/device_errors.py b/catapult/devil/devil/android/device_errors.py index e6893a4f..d1454683 100644 --- a/catapult/devil/devil/android/device_errors.py +++ b/catapult/devil/devil/android/device_errors.py @@ -1,7 +1,6 @@ # Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. - """ Exception classes raised by AdbWrapper and DeviceUtils. @@ -11,6 +10,7 @@ The class hierarchy for device exceptions is: +-- CommandFailedError | +-- AdbCommandFailedError | | +-- AdbShellCommandFailedError + | +-- AdbVersionError | +-- FastbootCommandFailedError | +-- DeviceVersionError | +-- DeviceChargingError @@ -48,7 +48,11 @@ class CommandFailedError(base_error.BaseError): class _BaseCommandFailedError(CommandFailedError): """Base Exception for adb and fastboot command failures.""" - def __init__(self, args, output, status=None, device_serial=None, + def __init__(self, + args, + output, + status=None, + device_serial=None, message=None): self.args = args self.output = output @@ -68,8 +72,7 @@ class _BaseCommandFailedError(CommandFailedError): def __eq__(self, other): return (super(_BaseCommandFailedError, self).__eq__(other) - and self.args == other.args - and self.output == other.output + and self.args == other.args and self.output == other.output and self.status == other.status) def __ne__(self, other): @@ -82,28 +85,42 @@ class _BaseCommandFailedError(CommandFailedError): result[:len(super_result)] = super_result # Update the args used to reconstruct this exception. - result[1] = ( - self.args, self.output, self.status, self.device_serial, self.message) + result[1] = (self.args, self.output, self.status, self.device_serial, + self.message) return tuple(result) class AdbCommandFailedError(_BaseCommandFailedError): """Exception for adb command failures.""" - def __init__(self, args, output, status=None, device_serial=None, + def __init__(self, + args, + output, + status=None, + device_serial=None, message=None): super(AdbCommandFailedError, self).__init__( - args, output, status=status, message=message, + args, + output, + status=status, + message=message, device_serial=device_serial) class FastbootCommandFailedError(_BaseCommandFailedError): """Exception for fastboot command failures.""" - def __init__(self, args, output, status=None, device_serial=None, + def __init__(self, + args, + output, + status=None, + device_serial=None, message=None): super(FastbootCommandFailedError, self).__init__( - args, output, status=status, message=message, + args, + output, + status=status, + message=message, device_serial=device_serial) @@ -114,13 +131,29 @@ class DeviceVersionError(CommandFailedError): super(DeviceVersionError, self).__init__(message, device_serial) +class AdbVersionError(CommandFailedError): + """Exception for running a command on an incompatible version of adb.""" + + def __init__(self, args, desc=None, actual_version=None, min_version=None): + adb_cmd = ' '.join(cmd_helper.SingleQuote(arg) for arg in args) + desc = desc or 'not supported' + if min_version: + desc += ' prior to %s' % min_version + if actual_version: + desc += ' (actual: %s)' % actual_version + super(AdbVersionError, + self).__init__(message='adb %s: %s' % (adb_cmd, desc)) + + class AdbShellCommandFailedError(AdbCommandFailedError): """Exception for shell command failures run via adb.""" def __init__(self, command, output, status, device_serial=None): self.command = command - segments = ['shell command run via adb failed on the device:\n', - ' command: %s\n' % command] + segments = [ + 'shell command run via adb failed on the device:\n', + ' command: %s\n' % command + ] segments.append(' exit status: %s\n' % status) if output: segments.append(' output:\n') @@ -133,7 +166,7 @@ class AdbShellCommandFailedError(AdbCommandFailedError): segments.append(" output: ''\n") message = ''.join(segments) super(AdbShellCommandFailedError, self).__init__( - ['shell', command], output, status, device_serial, message) + ['shell', command], output, status, device_serial, message) def __reduce__(self): """Support pickling.""" @@ -148,6 +181,7 @@ class AdbShellCommandFailedError(AdbCommandFailedError): class CommandTimeoutError(base_error.BaseError): """Exception for command timeouts.""" + def __init__(self, message, is_infra_error=False, output=None): super(CommandTimeoutError, self).__init__(message, is_infra_error) self.output = output @@ -171,8 +205,8 @@ class MultipleDevicesError(base_error.BaseError): def __init__(self, devices): parallel_devices = parallelizer.Parallelizer(devices) - descriptions = parallel_devices.pMap( - lambda d: d.build_description).pGet(None) + descriptions = parallel_devices.pMap(lambda d: d.build_description).pGet( + None) msg = ('More than one device available. Use -d/--device to select a device ' 'by serial.\n\nAvailable devices:\n') for d, desc in zip(devices, descriptions): |