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): | 17 def __init__(self, msg, device=None): |
18 super(CommandFailedError, self).__init__( | 18 super(CommandFailedError, self).__init__( |
19 '%s%s' % ('(device: %s) ' % device if device else '', msg)) | 19 '%s%s' % ('(device: %s) ' % device if device else '', msg)) |
20 | 20 |
21 | 21 |
22 class AdbCommandFailedError(CommandFailedError): | 22 class AdbCommandFailedError(CommandFailedError): |
23 """Exception for adb command failures.""" | 23 """Exception for adb command failures.""" |
24 | 24 |
25 def __init__(self, cmd, msg, device=None): | 25 def __init__(self, cmd, msg, device=None): |
26 super(AdbCommandFailedError, self).__init__( | 26 super(AdbCommandFailedError, self).__init__( |
27 'adb command \'%s\' failed with message: \'%s\'' % (' '.join(cmd), msg), | 27 'adb command %r failed with message: %r' % (' '.join(cmd), msg), |
28 device=device) | 28 device=device) |
29 | 29 |
30 | 30 |
31 class AdbShellCommandFailedError(CommandFailedError): | |
jbudorick
2014/10/17 09:04:53
This should inherit from AdbCommandFailedError.
perezju
2014/10/17 11:17:09
Done.
The new version will output something like:
| |
32 """Exception for adb shell command failing with non-zero return code.""" | |
33 | |
34 def __init__(self, cmd, return_code, output, device=None): | |
35 super(AdbShellCommandFailedError, self).__init__( | |
36 'adb shell command %r failed with return code %d and output %r' % | |
jbudorick
2014/10/17 09:04:53
You may want to rephrase this to distinguish the e
perezju
2014/10/17 11:17:09
That's what %r does :)
And the return code should
jbudorick
2014/10/17 15:48:00
Oh, neat. I didn't know about %r and somehow read
| |
37 (cmd, return_code, output), device=device) | |
38 self.return_code = return_code | |
39 self.output = output | |
40 | |
41 | |
31 class CommandTimeoutError(BaseError): | 42 class CommandTimeoutError(BaseError): |
32 """Exception for command timeouts.""" | 43 """Exception for command timeouts.""" |
33 pass | 44 pass |
34 | 45 |
35 | 46 |
36 class DeviceUnreachableError(BaseError): | 47 class DeviceUnreachableError(BaseError): |
37 """Exception for device unreachable failures.""" | 48 """Exception for device unreachable failures.""" |
38 pass | 49 pass |
39 | 50 |
40 | 51 |
41 class NoDevicesError(BaseError): | 52 class NoDevicesError(BaseError): |
42 """Exception for having no devices attached.""" | 53 """Exception for having no devices attached.""" |
43 | 54 |
44 def __init__(self): | 55 def __init__(self): |
45 super(NoDevicesError, self).__init__('No devices attached.') | 56 super(NoDevicesError, self).__init__('No devices attached.') |
46 | 57 |
OLD | NEW |