Re-land: content: Refactor GPU memory buffer framework.
[chromium-blink-merge.git] / build / android / pylib / device / device_errors.py
blob170637d5a3674c61c45347bdfcdb35ea4c61795f
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.
5 """
6 Exception classes raised by AdbWrapper and DeviceUtils.
7 """
9 from pylib import cmd_helper
12 class BaseError(Exception):
13 """Base exception for all device and command errors."""
14 pass
17 class CommandFailedError(BaseError):
18 """Exception for command failures."""
20 def __init__(self, message, device_serial=None):
21 if device_serial is not None:
22 message = '(device: %s) %s' % (device_serial, message)
23 self.device_serial = device_serial
24 super(CommandFailedError, self).__init__(message)
27 class AdbCommandFailedError(CommandFailedError):
28 """Exception for adb command failures."""
30 def __init__(self, cmd, output, status=None, device_serial=None):
31 self.cmd = cmd
32 self.output = output
33 self.status = status
34 message = []
35 if self.cmd[0] == 'shell':
36 assert len(self.cmd) == 2
37 message.append('adb shell command %r failed with' % self.cmd[1])
38 else:
39 command = ' '.join(cmd_helper.SingleQuote(arg) for arg in self.cmd)
40 message.append('adb command %r failed with' % command)
41 if status:
42 message.append(' exit status %d and' % self.status)
43 if output:
44 message.append(' output:\n')
45 message.extend('> %s\n' % line for line in output.splitlines())
46 else:
47 message.append(' no output')
48 super(AdbCommandFailedError, self).__init__(''.join(message), device_serial)
51 class CommandTimeoutError(BaseError):
52 """Exception for command timeouts."""
53 pass
56 class DeviceUnreachableError(BaseError):
57 """Exception for device unreachable failures."""
58 pass
61 class NoDevicesError(BaseError):
62 """Exception for having no devices attached."""
64 def __init__(self):
65 super(NoDevicesError, self).__init__('No devices attached.')