raise proper exception on undecode-able blobs

This commit is contained in:
Victor Shyba 2019-02-21 20:42:51 -03:00
parent aa40337ded
commit 4e7d88311f

View file

@ -131,7 +131,10 @@ class StreamDescriptor:
assert os.path.isfile(blob.file_path)
with open(blob.file_path, 'rb') as f:
json_bytes = f.read()
decoded = json.loads(json_bytes.decode())
try:
decoded = json.loads(json_bytes.decode())
except json.JSONDecodeError:
raise InvalidStreamDescriptorError("Does not decode as valid JSON")
if decoded['blobs'][-1]['length'] != 0:
raise InvalidStreamDescriptorError("Does not end with a zero-length blob.")
if any([blob_info['length'] == 0 for blob_info in decoded['blobs'][:-1]]):