[v4,7/7] dts: improve configuration errors
Checks
Commit Message
From: Luca Vizzarro <luca.vizzarro@arm.com>
Improve the way that configuration errors are displayed to the user.
Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@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(-)
Comments
Looks great, thanks Luca!
Reviewed-by: Dean Marx <dmarx@iol.unh.edu>
On 04/03/2025 22:39, Dean Marx wrote:
> Looks great, thanks Luca!
>
> Reviewed-by: Dean Marx <dmarx@iol.unh.edu>
Thank you for your review Dean!
@@ -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
@@ -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
@@ -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)