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 class BaseError(Exception): | 9 class BaseError(Exception): |
10 """Base exception for all device and command errors.""" | 10 """Base exception for all device and command errors.""" |
11 pass | 11 pass |
12 | 12 |
13 | 13 |
14 class CommandFailedError(BaseError): | 14 class CommandFailedError(BaseError): |
15 """Exception for command failures.""" | 15 """Exception for command failures.""" |
16 | 16 |
| 17 def __init__(self, msg, device=None): |
| 18 super(CommandFailedError, self).__init__( |
| 19 '%s%s' % ('(device: %s) ' % device if device else '', msg)) |
| 20 |
| 21 |
| 22 class AdbCommandFailedError(CommandFailedError): |
| 23 """Exception for adb command failures.""" |
| 24 |
17 def __init__(self, cmd, msg, device=None): | 25 def __init__(self, cmd, msg, device=None): |
18 super(CommandFailedError, self).__init__( | 26 super(AdbCommandFailedError, self).__init__( |
19 (('device %s: ' % device) if device else '') + | 27 'adb command \'%s\' failed with message: \'%s\'' % (' '.join(cmd), msg), |
20 'adb command \'%s\' failed with message: \'%s\'' % (' '.join(cmd), msg)) | 28 device=device) |
21 | 29 |
22 | 30 |
23 class CommandTimeoutError(BaseError): | 31 class CommandTimeoutError(BaseError): |
24 """Exception for command timeouts.""" | 32 """Exception for command timeouts.""" |
25 pass | 33 pass |
26 | 34 |
27 | 35 |
28 class DeviceUnreachableError(BaseError): | 36 class DeviceUnreachableError(BaseError): |
29 """Exception for device unreachable failures.""" | 37 """Exception for device unreachable failures.""" |
30 pass | 38 pass |
31 | 39 |
OLD | NEW |