Index: build/android/devil/android/forwarder.py |
diff --git a/build/android/devil/android/forwarder.py b/build/android/devil/android/forwarder.py |
index 8794797ffcebba3b7dc033a6d66c28fe379e7527..d3c2949d2937c7015f7c065ab0307f0564bec9d4 100644 |
--- a/build/android/devil/android/forwarder.py |
+++ b/build/android/devil/android/forwarder.py |
@@ -9,6 +9,7 @@ import logging |
import os |
import psutil |
+from devil import base_error |
from devil import devil_env |
from devil.android.constants import file_system |
from devil.android.valgrind_tools import base_tool |
@@ -40,6 +41,13 @@ class _FileLock(object): |
os.close(self._fd) |
+class HostForwarderError(base_error.BaseError): |
+ """Exception for failures involving host_forwarder.""" |
+ |
+ def __init__(self, message): |
+ super(HostForwarderError, self).__init__(message) |
+ |
+ |
class Forwarder(object): |
"""Thread-safe class to manage port forwards from the device to the host.""" |
@@ -90,8 +98,9 @@ class Forwarder(object): |
[instance._host_forwarder_path] + redirection_command) |
except OSError as e: |
if e.errno == 2: |
- raise Exception('Unable to start host forwarder. Make sure you have' |
- ' built host_forwarder.') |
+ raise HostForwarderError( |
+ 'Unable to start host forwarder. ' |
+ 'Make sure you have built host_forwarder.') |
else: raise |
if exit_code != 0: |
Forwarder._KillDeviceLocked(device, tool) |
@@ -101,12 +110,14 @@ class Forwarder(object): |
for line in ps_out: |
if 'device_forwarder' in line: |
logging.info(' %s', line) |
- raise Exception('%s exited with %d:\n%s' % ( |
- instance._host_forwarder_path, exit_code, '\n'.join(output))) |
+ raise HostForwarderError( |
+ '%s exited with %d:\n%s' % (instance._host_forwarder_path, |
+ exit_code, '\n'.join(output))) |
tokens = output.split(':') |
if len(tokens) != 2: |
- raise Exception('Unexpected host forwarder output "%s", ' |
- 'expected "device_port:host_port"' % output) |
+ raise HostForwarderError( |
+ 'Unexpected host forwarder output "%s", ' |
+ 'expected "device_port:host_port"' % output) |
device_port = int(tokens[0]) |
host_port = int(tokens[1]) |
serial_with_port = (device_serial, device_port) |
@@ -305,8 +316,9 @@ class Forwarder(object): |
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
['pkill', '-9', 'host_forwarder']) |
if exit_code != 0: |
- raise Exception('%s exited with %d:\n%s' % ( |
- self._host_forwarder_path, exit_code, '\n'.join(output))) |
+ raise HostForwarderError( |
+ '%s exited with %d:\n%s' % (self._host_forwarder_path, exit_code, |
+ '\n'.join(output))) |
@staticmethod |
def _KillDeviceLocked(device, tool): |