1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 09:47:58 +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
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:
data = b''.join(self._buffered_data)
while self._resync:
@ -791,10 +799,9 @@ def __next__(self):
self._unpacker = msgpack.Unpacker(object_hook=StableDict)
self._unpacker.feed(data)
try:
item = next(self._unpacker)
except (TypeError, ValueError, StopIteration):
# Ignore exceptions that might be raised when feeding
# msgpack with invalid data
item = unpack_next()
except (self.UnpackerCrashed, StopIteration):
# as long as we are resyncing, we also ignore StopIteration
pass
else:
if self.validator(item):
@ -802,10 +809,7 @@ def __next__(self):
return item
data = data[1:]
else:
try:
return next(self._unpacker)
except (TypeError, ValueError) as err:
raise self.UnpackerCrashed(str(err))
return unpack_next()
class ArchiveChecker: