summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2023-05-12 11:55:13 +0200
committerGitHub <noreply@github.com>2023-05-12 11:55:13 +0200
commitfd45839c04b1130a8da7ad31fa9abc316fd2ddf6 (patch)
treefaba1d96e5ed8377265a87aeb8f8836173f63c5d /lib
parent2e25db0755a4b765adce9d309c8d422975e81847 (diff)
downloadspack-fd45839c04b1130a8da7ad31fa9abc316fd2ddf6.tar.gz
spack-fd45839c04b1130a8da7ad31fa9abc316fd2ddf6.tar.bz2
spack-fd45839c04b1130a8da7ad31fa9abc316fd2ddf6.tar.xz
spack-fd45839c04b1130a8da7ad31fa9abc316fd2ddf6.zip
Improve error message for buildcaches (#37626)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/binary_distribution.py19
-rw-r--r--lib/spack/spack/database.py10
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index ca69695f11..06ed2ff5a5 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -193,10 +193,17 @@ class BinaryCacheIndex(object):
db_root_dir = os.path.join(tmpdir, "db_root")
db = spack_db.Database(None, db_dir=db_root_dir, enable_transaction_locking=False)
- self._index_file_cache.init_entry(cache_key)
- cache_path = self._index_file_cache.cache_path(cache_key)
- with self._index_file_cache.read_transaction(cache_key):
- db._read_from_file(cache_path)
+ try:
+ self._index_file_cache.init_entry(cache_key)
+ cache_path = self._index_file_cache.cache_path(cache_key)
+ with self._index_file_cache.read_transaction(cache_key):
+ 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)
@@ -2429,6 +2436,10 @@ class FetchIndexError(Exception):
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")
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index 9fa041ea35..47cdb51774 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -1654,8 +1654,14 @@ class InvalidDatabaseVersionError(SpackError):
"""Exception raised when the database metadata is newer than current Spack."""
def __init__(self, database, expected, found):
+ self.expected = expected
+ self.found = found
msg = (
- f"you need a newer Spack version to read the database in '{database.root}'. "
- f"The expected database version is '{expected}', but '{found}' was found."
+ f"you need a newer Spack version to read the DB in '{database.root}'. "
+ f"{self.database_version_message}"
)
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."