1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 18:28:42 +00:00

transform unpacker exception only at 1 place

This commit is contained in:
Thomas Waldmann 2016-07-28 22:23:38 +02:00
parent 852c583076
commit 97383e9e60

View file

@ -779,6 +779,14 @@ def __iter__(self):
return self return self
def __next__(self): def __next__(self):
def unpack_next():
try:
return next(self._unpacker)
except (TypeError, ValueError) as err:
# transform exceptions that might be raised when feeding
# msgpack with invalid data to a more specific exception
raise self.UnpackerCrashed(str(err))
if self._resync: if self._resync:
data = b''.join(self._buffered_data) data = b''.join(self._buffered_data)
while self._resync: while self._resync:
@ -791,10 +799,9 @@ def __next__(self):
self._unpacker = msgpack.Unpacker(object_hook=StableDict) self._unpacker = msgpack.Unpacker(object_hook=StableDict)
self._unpacker.feed(data) self._unpacker.feed(data)
try: try:
item = next(self._unpacker) item = unpack_next()
except (TypeError, ValueError, StopIteration): except (self.UnpackerCrashed, StopIteration):
# Ignore exceptions that might be raised when feeding # as long as we are resyncing, we also ignore StopIteration
# msgpack with invalid data
pass pass
else: else:
if self.validator(item): if self.validator(item):
@ -802,10 +809,7 @@ def __next__(self):
return item return item
data = data[1:] data = data[1:]
else: else:
try: return unpack_next()
return next(self._unpacker)
except (TypeError, ValueError) as err:
raise self.UnpackerCrashed(str(err))
class ArchiveChecker: class ArchiveChecker: