commit ce2d809ae979aad67d626437078f3a639597f9a6 Author: Damian Johnson atagar@torproject.org Date: Mon Nov 24 11:24:34 2014 -0800
Don't raise a ValueError when descriptor information is unavialable
Controller methods like get_network_status() raised a ValueError and pretty unhelpful error message when descriptor information is unavailable...
====================================================================== ERROR: test_get_network_status ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/atagar/Desktop/stem/test/integ/control/controller.py", line 1108, in test_get_network_status self.assertRaises(stem.ControllerError, controller.get_network_status, 'blargg') File "/usr/lib/python2.7/unittest/case.py", line 471, in assertRaises callableObj(*args, **kwargs) File "/home/atagar/Desktop/stem/stem/control.py", line 384, in wrapped raise exc ValueError: Router status entries (v3) must have a 'r' line:
I don't have a reliable repro for this, but I've seen it on occasion. We're not documented as raising ValueErrors, so raising a ControllerError instead with a slightly more descriptive message. --- stem/control.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/stem/control.py b/stem/control.py index 6e34ec0..1079629 100644 --- a/stem/control.py +++ b/stem/control.py @@ -1454,6 +1454,10 @@ class Controller(BaseController): raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
desc_content = self.get_info(query, get_bytes = True) + + if not desc_content: + raise stem.ControllerError("Descriptor information is unavailable, tor might still be downloading it") + return stem.descriptor.microdescriptor.Microdescriptor(desc_content)
@with_default(yields = True) @@ -1546,6 +1550,10 @@ class Controller(BaseController): raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
desc_content = self.get_info(query, get_bytes = True) + + if not desc_content: + raise stem.ControllerError("Descriptor information is unavailable, tor might still be downloading it") + return stem.descriptor.server_descriptor.RelayDescriptor(desc_content) except Exception as exc: if not self._is_server_descriptors_available(): @@ -1581,8 +1589,11 @@ class Controller(BaseController):
desc_content = self.get_info('desc/all-recent', get_bytes = True)
- if not desc_content and not self._is_server_descriptors_available(): - raise ValueError(SERVER_DESCRIPTORS_UNSUPPORTED) + if not desc_content: + if not self._is_server_descriptors_available(): + raise stem.ControllerError(SERVER_DESCRIPTORS_UNSUPPORTED) + else: + raise stem.ControllerError("Descriptor information is unavailable, tor might still be downloading it")
for desc in stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_content)): yield desc @@ -1655,6 +1666,9 @@ class Controller(BaseController):
desc_content = self.get_info(query, get_bytes = True)
+ if not desc_content: + raise stem.ControllerError("Descriptor information is unavailable, tor might still be downloading it") + if self.get_conf('UseMicrodescriptors', '0') == '1': return stem.descriptor.router_status_entry.RouterStatusEntryMicroV3(desc_content) else: @@ -1699,6 +1713,9 @@ class Controller(BaseController):
desc_content = self.get_info('ns/all', get_bytes = True)
+ if not desc_content: + raise stem.ControllerError("Descriptor information is unavailable, tor might still be downloading it") + desc_iterator = stem.descriptor.router_status_entry._parse_file( io.BytesIO(desc_content), True,