From 297329f4b5bb073cf16d886a7915b23c5f8dc723 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 11 May 2023 10:33:51 +0200 Subject: Improve error message for missing "command" entry in containerize (#37590) fixes #21242 --- lib/spack/spack/container/writers/__init__.py | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/container/writers/__init__.py b/lib/spack/spack/container/writers/__init__.py index 7508a67fd7..69a4b7f443 100644 --- a/lib/spack/spack/container/writers/__init__.py +++ b/lib/spack/spack/container/writers/__init__.py @@ -10,10 +10,12 @@ import copy from typing import Optional import spack.environment as ev +import spack.error import spack.schema.env import spack.tengine as tengine import spack.util.spack_yaml as syaml -from spack.container.images import ( + +from ..images import ( bootstrap_template_for, build_info, checkout_command, @@ -205,12 +207,20 @@ class PathContext(tengine.Context): @tengine.context_property def os_packages_final(self): """Additional system packages that are needed at run-time.""" - return self._os_packages_for_stage("final") + try: + return self._os_packages_for_stage("final") + except Exception as e: + msg = f"an error occurred while rendering the 'final' stage of the image: {e}" + raise spack.error.SpackError(msg) from e @tengine.context_property def os_packages_build(self): """Additional system packages that are needed at build-time.""" - return self._os_packages_for_stage("build") + try: + return self._os_packages_for_stage("build") + except Exception as e: + msg = f"an error occurred while rendering the 'build' stage of the image: {e}" + raise spack.error.SpackError(msg) from e @tengine.context_property def os_package_update(self): @@ -243,13 +253,24 @@ class PathContext(tengine.Context): if image is None: os_pkg_manager = os_package_manager_for(image_config["os"]) else: - os_pkg_manager = self.container_config["os_packages"]["command"] + os_pkg_manager = self._os_pkg_manager() update, install, clean = commands_for(os_pkg_manager) Packages = collections.namedtuple("Packages", ["update", "install", "list", "clean"]) return Packages(update=update, install=install, list=package_list, clean=clean) + def _os_pkg_manager(self): + try: + os_pkg_manager = self.container_config["os_packages"]["command"] + except KeyError: + msg = ( + "cannot determine the OS package manager to use.\n\n\tPlease add an " + "appropriate 'os_packages:command' entry to the spack.yaml manifest file\n" + ) + raise spack.error.SpackError(msg) + return os_pkg_manager + @tengine.context_property def extra_instructions(self): Extras = collections.namedtuple("Extra", ["build", "final"]) -- cgit v1.2.3-60-g2f50