Skip to content

Commit 4f91fb9

Browse files
authored
Check if downloaded file is empty (#385)
* Check if downloaded file is empty * pathlib
1 parent 77644aa commit 4f91fb9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pycytominer/cyto_utils/cell_locations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ def _download_s3(self, uri: str):
177177

178178
self.s3.download_file(bucket, key, tmp_file.name)
179179

180-
return tmp_file.name
180+
# Check if the downloaded file exists and has a size greater than 0
181+
tmp_file_path = pathlib.Path(tmp_file.name)
182+
if tmp_file_path.exists() and tmp_file_path.stat().st_size > 0:
183+
return tmp_file.name
184+
else:
185+
raise ValueError(
186+
f"Downloaded file '{tmp_file.name}' is empty or does not exist."
187+
)
181188

182189
def _load_metadata(self):
183190
"""Load the metadata into a Pandas DataFrame

0 commit comments

Comments
 (0)