OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 Exception classes raised by AdbWrapper and DeviceUtils. | 6 Exception classes raised by AdbWrapper and DeviceUtils. |
7 """ | 7 """ |
8 | 8 |
9 from pylib import cmd_helper | 9 from pylib import cmd_helper |
| 10 from pylib.utils import base_error |
10 | 11 |
11 | 12 |
12 class BaseError(Exception): | 13 class CommandFailedError(base_error.BaseError): |
13 """Base exception for all device and command errors.""" | |
14 pass | |
15 | |
16 | |
17 class CommandFailedError(BaseError): | |
18 """Exception for command failures.""" | 14 """Exception for command failures.""" |
19 | 15 |
20 def __init__(self, message, device_serial=None): | 16 def __init__(self, message, device_serial=None): |
21 if device_serial is not None: | 17 if device_serial is not None: |
22 message = '(device: %s) %s' % (device_serial, message) | 18 message = '(device: %s) %s' % (device_serial, message) |
23 self.device_serial = device_serial | 19 self.device_serial = device_serial |
24 super(CommandFailedError, self).__init__(message) | 20 super(CommandFailedError, self).__init__(message) |
25 | 21 |
26 | 22 |
27 class AdbCommandFailedError(CommandFailedError): | 23 class AdbCommandFailedError(CommandFailedError): |
(...skipping 29 matching lines...) Expand all Loading... |
57 if output: | 53 if output: |
58 message.append(' output:\n') | 54 message.append(' output:\n') |
59 message.extend(' - %s\n' % line for line in output.splitlines()) | 55 message.extend(' - %s\n' % line for line in output.splitlines()) |
60 else: | 56 else: |
61 message.append(" output: ''\n") | 57 message.append(" output: ''\n") |
62 message = ''.join(message) | 58 message = ''.join(message) |
63 super(AdbShellCommandFailedError, self).__init__( | 59 super(AdbShellCommandFailedError, self).__init__( |
64 ['shell', command], output, status, device_serial, message) | 60 ['shell', command], output, status, device_serial, message) |
65 | 61 |
66 | 62 |
67 class CommandTimeoutError(BaseError): | 63 class CommandTimeoutError(base_error.BaseError): |
68 """Exception for command timeouts.""" | 64 """Exception for command timeouts.""" |
69 pass | 65 pass |
70 | 66 |
71 | 67 |
72 class DeviceUnreachableError(BaseError): | 68 class DeviceUnreachableError(base_error.BaseError): |
73 """Exception for device unreachable failures.""" | 69 """Exception for device unreachable failures.""" |
74 pass | 70 pass |
75 | 71 |
76 | 72 |
77 class NoDevicesError(BaseError): | 73 class NoDevicesError(base_error.BaseError): |
78 """Exception for having no devices attached.""" | 74 """Exception for having no devices attached.""" |
79 | 75 |
80 def __init__(self): | 76 def __init__(self): |
81 super(NoDevicesError, self).__init__('No devices attached.') | 77 super(NoDevicesError, self).__init__('No devices attached.') |
82 | |
OLD | NEW |