Skip to content

Commit

Permalink
Raise InvalidRouterNickname in b.p.descriptors.parseNetworkStatusFile().
Browse files Browse the repository at this point in the history
For all other ValueErrors raised by Stem, we'll re-raise another
ValueError that reuses Stem's error message.

 * CHANGE bridgedb.parse.descriptors.parseNetworkStatusFile() to raise
   an InvalidRouterNickname exception if a router is parsed with a
   nickname which doesn't conform to torspec.
  • Loading branch information
isislovecruft committed Dec 28, 2014
1 parent 814e115 commit 28981fc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/bridgedb/parse/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from stem.descriptor.router_status_entry import RouterStatusEntryV3

from bridgedb import safelog
from bridgedb.parse.nickname import InvalidRouterNickname


class DescriptorWarning(Warning):
Expand Down Expand Up @@ -85,6 +86,9 @@ def parseNetworkStatusFile(filename, validate=True, skipAnnotations=True,
:param descriptorClass: A class (probably from
:api:`stem.descriptors.router_status_entry`) which Stem will parse
each descriptor it reads from **filename** into.
:raises InvalidRouterNickname: if one of the routers in the networkstatus
file had a nickname which does not conform to Tor's nickname
specification.
:raises ValueError: if the contents of a descriptor are malformed and
**validate** is ``True``.
:raises IOError: if the file at **filename** can't be read.
Expand All @@ -103,7 +107,15 @@ def parseNetworkStatusFile(filename, validate=True, skipAnnotations=True,
logging.debug("Skipping %d bytes of networkstatus file." % position)
fh.seek(position)
document = _parseNSFile(fh, validate, entry_class=descriptorClass)
routers.extend(list(document))

try:
routers.extend(list(document))
except ValueError as error:
if "nickname isn't valid" in str(error):
raise InvalidRouterNickname(str(error))
else:
raise ValueError(str(error))

logging.info("Closed networkstatus file: %s" % filename)

return routers
Expand Down

0 comments on commit 28981fc

Please sign in to comment.