Skip to content

Commit

Permalink
Validation: Check for filesystem errors when reading a file fails
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Dec 13, 2023
1 parent 88b5725 commit d8044d6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions extra_data/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,19 @@ def _check_file(args):
try:
fa = FileAccess(filepath)
except Exception as e:
problems.append(
dict(msg="Could not open file", file=filepath, error=e)
)
try:
with open(filepath, "rb") as f:
f.read(16)
except OSError as e2:
# Filesystem issue, e.g. dCache node down. HDF5 errors can be
# confusing, so record the OS error instead.
problems.append(
dict(msg="Could not access file", file=filepath, error=e2)
)
else:
problems.append(
dict(msg="Could not open HDF5 file", file=filepath, error=e)
)
return filename, None, problems
else:
fv = FileValidator(fa)
Expand Down Expand Up @@ -328,7 +338,12 @@ def main(argv=None):
validator = RunValidator(path, term_progress=True)
else:
print("Checking file:", path)
validator = FileValidator(H5File(path).files[0])
_, fa, problems = _check_file(os.path.split(path))
if problems:
print(str(ValidationError(problems)))
return 1

validator = FileValidator(fa)

try:
validator.run_checks()
Expand Down

0 comments on commit d8044d6

Please sign in to comment.