Improve error message for buildcaches (#37626)

This commit is contained in:
Massimiliano Culpo 2023-05-12 11:55:13 +02:00 committed by GitHub
parent 2e25db0755
commit fd45839c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View file

@ -193,10 +193,17 @@ def _associate_built_specs_with_mirror(self, cache_key, mirror_url):
db_root_dir = os.path.join(tmpdir, "db_root") db_root_dir = os.path.join(tmpdir, "db_root")
db = spack_db.Database(None, db_dir=db_root_dir, enable_transaction_locking=False) db = spack_db.Database(None, db_dir=db_root_dir, enable_transaction_locking=False)
try:
self._index_file_cache.init_entry(cache_key) self._index_file_cache.init_entry(cache_key)
cache_path = self._index_file_cache.cache_path(cache_key) cache_path = self._index_file_cache.cache_path(cache_key)
with self._index_file_cache.read_transaction(cache_key): with self._index_file_cache.read_transaction(cache_key):
db._read_from_file(cache_path) db._read_from_file(cache_path)
except spack_db.InvalidDatabaseVersionError as e:
msg = (
f"you need a newer Spack version to read the buildcache index for the "
f"following mirror: '{mirror_url}'. {e.database_version_message}"
)
raise BuildcacheIndexError(msg) from e
spec_list = db.query_local(installed=False, in_buildcache=True) spec_list = db.query_local(installed=False, in_buildcache=True)
@ -2429,6 +2436,10 @@ def __str__(self):
return "{}, due to: {}".format(self.args[0], self.args[1]) return "{}, due to: {}".format(self.args[0], self.args[1])
class BuildcacheIndexError(spack.error.SpackError):
"""Raised when a buildcache cannot be read for any reason"""
FetchIndexResult = collections.namedtuple("FetchIndexResult", "etag hash data fresh") FetchIndexResult = collections.namedtuple("FetchIndexResult", "etag hash data fresh")

View file

@ -1654,8 +1654,14 @@ class InvalidDatabaseVersionError(SpackError):
"""Exception raised when the database metadata is newer than current Spack.""" """Exception raised when the database metadata is newer than current Spack."""
def __init__(self, database, expected, found): def __init__(self, database, expected, found):
self.expected = expected
self.found = found
msg = ( msg = (
f"you need a newer Spack version to read the database in '{database.root}'. " f"you need a newer Spack version to read the DB in '{database.root}'. "
f"The expected database version is '{expected}', but '{found}' was found." f"{self.database_version_message}"
) )
super(InvalidDatabaseVersionError, self).__init__(msg) super(InvalidDatabaseVersionError, self).__init__(msg)
@property
def database_version_message(self):
return f"The expected DB version is '{self.expected}', but '{self.found}' was found."