Skip to content

Commit 24cafad

Browse files
🔨 [dataset] Handle corrupted cached file in PersistentDataset (#7244)
Fixes #5723 ### Description Corrupted cached files in the PersistentDataset cause the exception: `RuntimeError: Invalid magic number; corrupt file?` With this PR we handle that case in the try-except block and continue the usual functionality if the cached file was absent. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [x] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Ishan Dutta <ishandutta0098@gmail.com> Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
1 parent 882482b commit 24cafad

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

monai/data/dataset.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ def _cachecheck(self, item_transformed):
387387
except PermissionError as e:
388388
if sys.platform != "win32":
389389
raise e
390+
except RuntimeError as e:
391+
if "Invalid magic number; corrupt file" in str(e):
392+
warnings.warn(f"Corrupt cache file detected: {hashfile}. Deleting and recomputing.")
393+
hashfile.unlink()
394+
else:
395+
raise e
390396

391397
_item_transformed = self._pre_transform(deepcopy(item_transformed)) # keep the original hashed
392398
if hashfile is None:

0 commit comments

Comments
 (0)