Improve error message for buildcaches (#37626)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							2e25db0755
						
					
				
				
					commit
					fd45839c04
				
			@@ -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 = spack_db.Database(None, db_dir=db_root_dir, enable_transaction_locking=False)
 | 
			
		||||
 | 
			
		||||
            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 @@ def __str__(self):
 | 
			
		||||
            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")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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."
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user