Catch corrupt data
This commit is contained in:
parent
93307ad1ec
commit
09a9390c92
1 changed files with 6 additions and 2 deletions
|
@ -7,7 +7,7 @@ from mmap import mmap, PROT_READ, PROT_WRITE
|
|||
from typing import TypeVar, Generic, Callable, List
|
||||
|
||||
import mmh3
|
||||
from zstandard import ZstdDecompressor, ZstdCompressor
|
||||
from zstandard import ZstdDecompressor, ZstdCompressor, ZstdError
|
||||
|
||||
VERSION = 1
|
||||
METADATA_CONSTANT = b'mwmbl-tiny-search'
|
||||
|
@ -128,7 +128,11 @@ class TinyIndex(Generic[T]):
|
|||
|
||||
def _get_page_tuples(self, i):
|
||||
page_data = self.mmap[i * self.page_size:(i + 1) * self.page_size]
|
||||
decompressed_data = self.decompressor.decompress(page_data)
|
||||
try:
|
||||
decompressed_data = self.decompressor.decompress(page_data)
|
||||
except ZstdError:
|
||||
logger.exception(f"Error decompressing page data, content: {page_data}")
|
||||
return []
|
||||
# logger.debug(f"Decompressed data: {decompressed_data}")
|
||||
return json.loads(decompressed_data.decode('utf8'))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue