From: Luca Vizzarro <luca.vizza...@arm.com> Improve the way that configuration errors are displayed to the user.
Signed-off-by: Luca Vizzarro <luca.vizza...@arm.com> Reviewed-by: Paul Szczepanek <paul.szczepa...@arm.com> --- dts/framework/config/__init__.py | 4 ++-- dts/framework/config/test_run.py | 2 +- dts/framework/runner.py | 14 +++++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dts/framework/config/__init__.py b/dts/framework/config/__init__.py index 129e6f3222..1ec744d1d4 100644 --- a/dts/framework/config/__init__.py +++ b/dts/framework/config/__init__.py @@ -141,7 +141,7 @@ def _load_and_parse_model(file_path: Path, model_type: type[T], ctx: ValidationC data = yaml.safe_load(f) return TypeAdapter(model_type).validate_python(data, context=cast(dict[str, Any], ctx)) except ValidationError as e: - msg = f"failed to load the configuration file {file_path}" + msg = f"Failed to load the configuration file {file_path}." raise ConfigurationError(msg) from e @@ -190,4 +190,4 @@ def load_config(ctx: ValidationContext) -> Configuration: {"test_run": test_run, "nodes": nodes, "tests_config": dict(tests_config)}, context=ctx ) except ValidationError as e: - raise ConfigurationError("the configurations supplied are invalid") from e + raise ConfigurationError("The configurations supplied are invalid.") from e diff --git a/dts/framework/config/test_run.py b/dts/framework/config/test_run.py index 688688e88e..06fe28143c 100644 --- a/dts/framework/config/test_run.py +++ b/dts/framework/config/test_run.py @@ -445,7 +445,7 @@ def use_first_core(self) -> bool: class DPDKConfiguration(DPDKRuntimeConfiguration): """The DPDK configuration needed to test.""" - #: The DPDKD build configuration used to test. + #: The DPDK build configuration used to test. build: DPDKBuildConfiguration diff --git a/dts/framework/runner.py b/dts/framework/runner.py index f822e8a8fc..f20aa3576a 100644 --- a/dts/framework/runner.py +++ b/dts/framework/runner.py @@ -11,8 +11,10 @@ import os import sys +import textwrap from framework.config.common import ValidationContext +from framework.exception import ConfigurationError from framework.test_run import TestRun from framework.testbed_model.node import Node @@ -37,7 +39,17 @@ class DTSRunner: def __init__(self): """Initialize the instance with configuration, logger, result and string constants.""" - self._configuration = load_config(ValidationContext(settings=SETTINGS)) + try: + self._configuration = load_config(ValidationContext(settings=SETTINGS)) + except ConfigurationError as e: + if e.__cause__: + print(f"{e} Reason:", file=sys.stderr) + print(file=sys.stderr) + print(textwrap.indent(str(e.__cause__), prefix=" " * 2), file=sys.stderr) + else: + print(e, file=sys.stderr) + sys.exit(e.severity) + self._logger = get_dts_logger() if not os.path.exists(SETTINGS.output_dir): os.makedirs(SETTINGS.output_dir) -- 2.43.0