[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] scanner, destination: Log all possible exceptions



commit c4f502c1d05570d6069680b3a91cf9a1709d6e7a
Author: juga0 <juga@xxxxxxxxxx>
Date:   Wed Feb 27 17:30:59 2019 +0000

    scanner, destination: Log all possible exceptions
    
    that can happen from requests, so that they can later be stored in
    a Result.
---
 sbws/core/scanner.py    | 8 ++------
 sbws/lib/destination.py | 5 +----
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index e99b8cd..3fbd378 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -84,8 +84,6 @@ def timed_recv_from_server(session, dest, byte_range):
 
     start_time = time.time()
     HTTP_GET_HEADERS['Range'] = byte_range
-    # TODO:
-    # - What other exceptions can this throw?
     # - response.elapsed "measures the time taken between sending the first
     #   byte of the request and finishing parsing the headers.
     #   It is therefore unaffected by consuming the response content"
@@ -94,10 +92,8 @@ def timed_recv_from_server(session, dest, byte_range):
     try:
         # headers are merged with the session ones, not overwritten.
         session.get(dest.url, headers=HTTP_GET_HEADERS, verify=dest.verify)
-    # NewConnectionError will be raised when shutting down.
-    except (requests.exceptions.ConnectionError,
-            requests.exceptions.ReadTimeout,
-            requests.exceptions.NewConnectionError) as e:
+    # Catch any `requests` exception, so that it can stored in the Result
+    except requests.exceptions.RequestException as e:
         log.debug(e)
         return False, e
     end_time = time.time()
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index e1be0bb..c0e6b03 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -76,11 +76,8 @@ def connect_to_destination_over_circuit(dest, circ_id, session, cont, max_dl):
         listener = stem_utils.attach_stream_to_circuit_listener(cont, circ_id)
         stem_utils.add_event_listener(cont, listener, EventType.STREAM)
         try:
-            # TODO:
-            # - What other exceptions can this throw?
             head = session.head(dest.url, verify=dest.verify)
-        except (requests.exceptions.ConnectionError,
-                requests.exceptions.ReadTimeout) as e:
+        except requests.exceptions.RequestException as e:
             dest.set_failure()
             return False, 'Could not connect to {} over circ {} {}: {}'.format(
                 dest.url, circ_id, stem_utils.circuit_str(cont, circ_id), e)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits