Without this check, corrupt files would raise a Python exception, now early exit with a useful error.