Skip to content

Commit 877cec0

Browse files
committed
Fix unbound local error when reading corrupted metadata files (#3610)
1 parent 8519f0d commit 877cec0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/huggingface_hub/_local_folder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def read_download_metadata(local_dir: Path, filename: str) -> Optional[LocalDown
308308
paths.metadata_path.unlink()
309309
except Exception as e:
310310
logger.warning(f"Could not remove corrupted metadata file {paths.metadata_path}: {e}")
311+
return None
311312

312313
try:
313314
# check if the file exists and hasn't been modified since the metadata was saved
@@ -383,6 +384,9 @@ def read_upload_metadata(local_dir: Path, filename: str) -> LocalUploadFileMetad
383384
except Exception as e:
384385
logger.warning(f"Could not remove corrupted metadata file {paths.metadata_path}: {e}")
385386

387+
# corrupted metadata => we don't know anything expect its size
388+
return LocalUploadFileMetadata(size=paths.file_path.stat().st_size)
389+
386390
# TODO: can we do better?
387391
if (
388392
metadata.timestamp is not None

0 commit comments

Comments
 (0)