[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / build / android / pylib / device / device_errors.py
blob26d9eaf48b71c4c48a7b3cfa48a436b98fc70f07
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
10 from pylib.utils import base_error
13 class CommandFailedError(base_error.BaseError):
14 """Exception for command failures."""
16 def __init__(self, message, device_serial=None):
17 if device_serial is not None:
18 message = '(device: %s) %s' % (device_serial, message)
19 self.device_serial = device_serial
20 super(CommandFailedError, self).__init__(message)
23 class AdbCommandFailedError(CommandFailedError):
24 """Exception for adb command failures."""
26 def __init__(self, args, output, status=None, device_serial=None,
27 message=None):
28 self.args = args
29 self.output = output
30 self.status = status
31 if not message:
32 adb_cmd = ' '.join(cmd_helper.SingleQuote(arg) for arg in self.args)
33 message = ['adb %s: failed ' % adb_cmd]
34 if status:
35 message.append('with exit status %s ' % self.status)
36 if output:
37 message.append('and output:\n')
38 message.extend('- %s\n' % line for line in output.splitlines())
39 else:
40 message.append('and no output.')
41 message = ''.join(message)
42 super(AdbCommandFailedError, self).__init__(message, device_serial)
45 class AdbShellCommandFailedError(AdbCommandFailedError):
46 """Exception for shell command failures run via adb."""
48 def __init__(self, command, output, status, device_serial=None):
49 self.command = command
50 message = ['shell command run via adb failed on the device:\n',
51 ' command: %s\n' % command]
52 message.append(' exit status: %s\n' % status)
53 if output:
54 message.append(' output:\n')
55 message.extend(' - %s\n' % line for line in output.splitlines())
56 else:
57 message.append(" output: ''\n")
58 message = ''.join(message)
59 super(AdbShellCommandFailedError, self).__init__(
60 ['shell', command], output, status, device_serial, message)
63 class CommandTimeoutError(base_error.BaseError):
64 """Exception for command timeouts."""
65 pass
68 class DeviceUnreachableError(base_error.BaseError):
69 """Exception for device unreachable failures."""
70 pass
73 class NoDevicesError(base_error.BaseError):
74 """Exception for having no devices attached."""
76 def __init__(self):
77 super(NoDevicesError, self).__init__('No devices attached.')