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 from pylib
import cmd_helper
12 class BaseError(Exception):
13 """Base exception for all device and command errors."""
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):
35 if self
.cmd
[0] == 'shell':
36 assert len(self
.cmd
) == 2
37 message
.append('adb shell command %r failed with' % self
.cmd
[1])
39 command
= ' '.join(cmd_helper
.SingleQuote(arg
) for arg
in self
.cmd
)
40 message
.append('adb command %r failed with' % command
)
42 message
.append(' exit status %d and' % self
.status
)
44 message
.append(' output:\n')
45 message
.extend('> %s\n' % line
for line
in output
.splitlines())
47 message
.append(' no output')
48 super(AdbCommandFailedError
, self
).__init
__(''.join(message
), device_serial
)
51 class CommandTimeoutError(BaseError
):
52 """Exception for command timeouts."""
56 class DeviceUnreachableError(BaseError
):
57 """Exception for device unreachable failures."""
61 class NoDevicesError(BaseError
):
62 """Exception for having no devices attached."""
65 super(NoDevicesError
, self
).__init
__('No devices attached.')