From 2503ab39cd32f469453d1123921101d88d117a3f Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Thu, 4 May 2023 04:50:19 +0200 Subject: [PATCH] menu plugin: handle common KConfig errors This patch handles common Kconfig errors (file not found, invalid config) and reports them as user errors. By that, the root cause of the error is easier to spot by the user. Signed-off-by: Felix Moessbauer Signed-off-by: Jan Kiszka --- kas/plugins/menu.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kas/plugins/menu.py b/kas/plugins/menu.py index 9618e6b..03548d2 100644 --- a/kas/plugins/menu.py +++ b/kas/plugins/menu.py @@ -70,8 +70,8 @@ import logging import os import pprint import yaml -from kconfiglib import Kconfig, Symbol, Choice, expr_value, TYPE_TO_STR, \ - MENU, COMMENT, STRING, BOOL, INT, HEX, UNKNOWN +from kconfiglib import Kconfig, Symbol, Choice, KconfigError, \ + expr_value, TYPE_TO_STR, MENU, COMMENT, STRING, BOOL, INT, HEX, UNKNOWN from kas import __version__, __file_version__ from kas.context import create_global_context from kas.config import CONFIG_YAML_FILE @@ -100,6 +100,13 @@ class MissingModuleError(KasUserError): pass +class KConfigLoadError(KasUserError): + """ + The KConfig file could not be found or is invalid + """ + pass + + def check_sym_is_string(sym): if sym.type != STRING: raise VariableTypeError('Variable {} must be of string type' @@ -253,7 +260,10 @@ class Menu: ctx = create_global_context(args) - self.kconf = Kconfig(args.kconfig, warn_to_stderr=False) + try: + self.kconf = Kconfig(args.kconfig, warn_to_stderr=False) + except (KconfigError, FileNotFoundError) as err: + raise KConfigLoadError(str(err)) config_filename = os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE)