Skip to content

Commit aaf6564

Browse files
committed
Improve error when checksum dict has no entry for a file
When the dict didn't contain the filename EB will crash with > Invalid checksum spec 'None', should be a string (MD5) or 2-tuple (type, value). This will now raise a more descriptive error
1 parent 2436f4d commit aaf6564

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

easybuild/tools/filetools.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,14 +1265,11 @@ def verify_checksum(path, checksums):
12651265

12661266
for checksum in checksums:
12671267
if isinstance(checksum, dict):
1268-
if filename in checksum:
1268+
try:
12691269
# Set this to a string-type checksum
12701270
checksum = checksum[filename]
1271-
elif build_option('enforce_checksums'):
1272-
raise EasyBuildError("Missing checksum for %s", filename)
1273-
else:
1274-
# Set to None and allow to fail elsewhere
1275-
checksum = None
1271+
except KeyError:
1272+
raise EasyBuildError("Missing checksum for %s in %s", filename, checksum)
12761273

12771274
if isinstance(checksum, string_type):
12781275
# if no checksum type is specified, it is assumed to be MD5 (32 characters) or SHA256 (64 characters)

test/framework/filetools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ def test_checksums(self):
348348
alt_checksums = ('7167b64b1ca062b9674ffef46f9325db7167b64b1ca062b9674ffef46f9325db', broken_checksums['sha256'])
349349
self.assertFalse(ft.verify_checksum(fp, alt_checksums))
350350

351+
# Check dictionary
352+
alt_checksums = (known_checksums['sha256'],)
353+
self.assertTrue(ft.verify_checksum(fp, {os.path.basename(fp): known_checksums['sha256']}))
354+
faulty_dict = {'wrong-name': known_checksums['sha256']}
355+
self.assertErrorRegex(EasyBuildError,
356+
"Missing checksum for " + os.path.basename(fp) + " in .*wrong-name.*",
357+
ft.verify_checksum, fp, faulty_dict)
358+
351359
# check whether missing checksums are enforced
352360
build_options = {
353361
'enforce_checksums': True,
@@ -362,6 +370,8 @@ def test_checksums(self):
362370
for checksum in [known_checksums[x] for x in ('md5', 'sha256')]:
363371
dict_checksum = {os.path.basename(fp): checksum, 'foo': 'baa'}
364372
self.assertTrue(ft.verify_checksum(fp, dict_checksum))
373+
del dict_checksum[os.path.basename(fp)]
374+
self.assertErrorRegex(EasyBuildError, "Missing checksum for", ft.verify_checksum, fp, dict_checksum)
365375

366376
def test_common_path_prefix(self):
367377
"""Test get common path prefix for a list of paths."""

0 commit comments

Comments
 (0)