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

[tor-commits] [stem/master] Separate Query exception attributes



commit aebf3e4e573858b0a4f77939429c89700a07c78c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Jan 2 13:56:21 2019 -0800

    Separate Query exception attributes
    
    Oops, commit cc43a6c both broke our unit tests and is incorrect in that it
    changes the Query's 'error' attribute to a completely different type.
    
    The error attribute is public so we cannot change it. Simply storing exception
    metadata as a separate private attribute for the time being. In stem 2.x we'll
    be able to drop this whole thing because without requiring python 2.x
    compatibility we can re-raise exceptions while retaining their stacktrace.
---
 stem/descriptor/remote.py      | 11 +++++++----
 test/unit/descriptor/remote.py |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 20622cce..9ccfaced 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -423,7 +423,8 @@ class Query(object):
     self.fall_back_to_authority = fall_back_to_authority
 
     self.content = None
-    self.error = None
+    self.error = None  # TODO: maybe remove in favor of error_attr in stem 2.x
+    self._error_attr = None
     self.is_done = False
     self.download_url = None
 
@@ -518,7 +519,7 @@ class Query(object):
         # When we drop python 2.x support we should replace this with the
         # 'raise from' option above.
 
-        exc_type, exc_value, exc_traceback = self.error
+        exc_type, exc_value, exc_traceback = self._error_attr
         stacktrace = 'Original traceback:\n' + ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)[1:])
 
         raise exc_type(str(exc_value) + '\n\n' + stacktrace)
@@ -552,7 +553,8 @@ class Query(object):
           for desc in results:
             yield desc
         except ValueError as exc:
-          self.error = sys.exc_info()  # encountered a parsing error
+          self.error = exc  # encountered a parsing error
+          self._error_attr = sys.exc_info()
 
           if suppress:
             return
@@ -606,7 +608,8 @@ class Query(object):
         return self._download_descriptors(retries - 1, timeout)
       else:
         log.debug("Unable to download descriptors from '%s': %s" % (self.download_url, exc))
-        self.error = sys.exc_info()
+        self.error = exc
+        self._error_attr = sys.exc_info()
     finally:
       self.is_done = True
 
diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py
index aab5f5d6..d2688775 100644
--- a/test/unit/descriptor/remote.py
+++ b/test/unit/descriptor/remote.py
@@ -162,7 +162,7 @@ class TestDescriptorDownloader(unittest.TestCase):
         validate = True,
       )
 
-      self.assertRaisesWith(stem.ProtocolError, "Response should begin with HTTP success, but was 'HTTP/1.0 500 Kaboom'", request.run)
+      self.assertRaisesRegexp(stem.ProtocolError, "^Response should begin with HTTP success, but was 'HTTP/1.0 500 Kaboom'", request.run)
 
   @patch(URL_OPEN, _dirport_mock(TEST_DESCRIPTOR))
   def test_using_dirport(self):

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