From 97c034eedf7bdb5514b76e2025c26c77e472b6a5 Mon Sep 17 00:00:00 2001 From: Adam Kariv Date: Sun, 9 Jun 2024 13:09:14 +0300 Subject: [PATCH] Exception handling on s3 store --- odds/common/store/s3/s3_store.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/odds/common/store/s3/s3_store.py b/odds/common/store/s3/s3_store.py index aa6229d..7ca9c2a 100644 --- a/odds/common/store/s3/s3_store.py +++ b/odds/common/store/s3/s3_store.py @@ -67,17 +67,21 @@ async def getDataset(self, datasetId: str) -> Dataset: except Exception as e: print('NOT FOUND', key, e) return None - content = await obj.get() - content = await content['Body'].read() - data = json.loads(content.decode('utf-8')) - resources = data.pop('resources', []) - for resource in resources: - resource['fields'] = [Field(**f) for f in resource['fields']] - data['resources'] = [Resource(**r) for r in resources] - if 'embedding' in data: - data['status_embedding'] = bool(data.pop('embedding')) - dataset = Dataset(**data) - return dataset + try: + content = await obj.get() + content = await content['Body'].read() + data = json.loads(content.decode('utf-8')) + resources = data.pop('resources', []) + for resource in resources: + resource['fields'] = [Field(**f) for f in resource['fields']] + data['resources'] = [Resource(**r) for r in resources] + if 'embedding' in data: + data['status_embedding'] = bool(data.pop('embedding')) + dataset = Dataset(**data) + return dataset + except Exception as e: + print('FAILED TO LOAD', key, e) + return None async def hasDataset(self, datasetId: str) -> bool: async with self.bucket() as bucket: