[v4,7/7] dts: improve configuration errors

Message ID 20250303145709.126126-8-Luca.Vizzarro@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Paul Szczepanek
Headers
Series dts: add per-test-suite configuration |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation warning apply issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS

Commit Message

Luca Vizzarro March 3, 2025, 2:57 p.m. UTC
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

Dean Marx March 4, 2025, 8:39 p.m. UTC | #1
Looks great, thanks Luca!

Reviewed-by: Dean Marx <dmarx@iol.unh.edu>
  
Luca Vizzarro March 11, 2025, 12:42 p.m. UTC | #2
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!
  

Patch

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)