Bug 1413852 - Improve failure message for socket connection attempts. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 02 Nov 2017 12:03:03 +0100
changeset 692043 bd3cd88269d0da7b27bbf324dbb93c255879b9c4
parent 692030 6daafc8145adb77c5a786dc8bd0e7060fc66f374
child 738642 34b25c26e501ab336a01b39d4bf2cb9829a43e97
push id87376
push userbmo:hskupin@gmail.com
push dateThu, 02 Nov 2017 12:33:15 +0000
bugs1413852
milestone58.0a1
Bug 1413852 - Improve failure message for socket connection attempts. Instead of a general socket timeout failure indicate that no hello data has been received through the socket right after the call to connect(). MozReview-Commit-ID: EPNiCLNyFFH
testing/marionette/client/marionette_driver/transport.py
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -1,14 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import json
 import socket
+import sys
 import time
 
 
 class SocketTimeout(object):
     def __init__(self, socket, timeout):
         self.sock = socket
         self.timeout = timeout
         self.old_timeout = None
@@ -191,20 +192,27 @@ class TcpTransport(object):
 
             self.sock.connect((self.addr, self.port))
         except:
             # Unset self.sock so that the next attempt to send will cause
             # another connection attempt.
             self.sock = None
             raise
 
-        with SocketTimeout(self.sock, 60.0):
-            # first packet is always a JSON Object
-            # which we can use to tell which protocol level we are at
-            raw = self.receive(unmarshal=False)
+        try:
+            with SocketTimeout(self.sock, 60.0):
+                # first packet is always a JSON Object
+                # which we can use to tell which protocol level we are at
+                raw = self.receive(unmarshal=False)
+        except socket.timeout:
+            msg = "Connection attempt failed because no data has been received over the socket: {}"
+            exc, val, tb = sys.exc_info()
+
+            raise exc, msg.format(val), tb
+
         hello = json.loads(raw)
         self.protocol = hello.get("marionetteProtocol", self.min_protocol_level)
         self.application_type = hello.get("applicationType")
 
         return (self.protocol, self.application_type)
 
     def send(self, obj):
         """Send message to the remote server.  Allowed input is a