Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2190)

Unified Diff: build/android/devil/android/forwarder.py

Issue 1636953002: [Android] Revise host_forwarder exception type & failure handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/android/pylib/local/device/local_device_test_run.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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):
« no previous file with comments | « no previous file | build/android/pylib/local/device/local_device_test_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698