1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 Exception classes raised by AdbWrapper and DeviceUtils.
9 class BaseError(Exception):
10 """Base exception for all device and command errors."""
14 class CommandFailedError(BaseError):
15 """Exception for command failures."""
17 def __init__(self, msg, device=None):
18 super(CommandFailedError, self).__init__(
19 '%s%s' % ('(device: %s) ' % device if device else '', msg))
22 class AdbCommandFailedError(CommandFailedError):
23 """Exception for adb command failures."""
25 def __init__(self, cmd, msg, device=None):
26 super(AdbCommandFailedError, self).__init__(
27 'adb command %r failed with message: %s' % (' '.join(cmd), msg),
31 class AdbShellCommandFailedError(AdbCommandFailedError):
32 """Exception for adb shell command failing with non-zero return code."""
34 def __init__(self, cmd, return_code, output, device=None):
35 super(AdbShellCommandFailedError, self).__init__(
37 'command %r on device failed with return code %d and output %r'
38 % (cmd, return_code, output),
40 self.return_code = return_code
44 class CommandTimeoutError(BaseError):
45 """Exception for command timeouts."""
49 class DeviceUnreachableError(BaseError):
50 """Exception for device unreachable failures."""
54 class NoDevicesError(BaseError):
55 """Exception for having no devices attached."""
58 super(NoDevicesError, self).__init__('No devices attached.')