Commit cc7c1c91 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[data] Turn asserts into proper exception

parent 4b9ec99c
......@@ -1071,9 +1071,10 @@ def load_data_index(cache_root, hash_path):
candidates = glob.glob(index_glob)
assert candidates, ( # nosec
"No index file matching the pattern `%s' found." % index_glob
)
if not candidates:
raise RuntimeError(
"No index file matching the pattern `%s' found." % index_glob
)
retval = []
end_index = 0
......@@ -1083,19 +1084,17 @@ def load_data_index(cache_root, hash_path):
start = [int(k[0]) for k in data]
end = int(data[-1][1]) # last index
# checks if the sum exists and is correct, only appends in that case
# returns an empty list otherwise, as these indices are considered
# invalid.
# Checks if the sum exists and is correct
expected_chksum = open(filename + ".checksum", "rt").read().strip()
current_chksum = hashFileContents(filename)
assert expected_chksum == current_chksum, ( # nosec
"index file `%s' has a "
"checksum (%s) that differs from expected one (%s)"
% (filename, current_chksum, expected_chksum)
)
if expected_chksum != current_chksum:
raise RuntimeError(
"index file `%s' has a "
"checksum (%s) that differs from expected one (%s)"
% (filename, current_chksum, expected_chksum)
)
# else, group indices
retval.extend(start)
if end > end_index:
end_index = end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment