From 89a6198fdc731eb102f4e458f7e2027f1ac17f4d Mon Sep 17 00:00:00 2001 From: Frode Helgetun Krogh <70878501+frodehk@users.noreply.github.com> Date: Wed, 13 Sep 2023 12:25:14 +0200 Subject: [PATCH] ECALC-21 chore: improve dto validation error message (#168) * chore: add component name to dto validation error message --- .../libecalc/common/libecalc/input/validation_errors.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ecalc/libraries/libecalc/common/libecalc/input/validation_errors.py b/src/ecalc/libraries/libecalc/common/libecalc/input/validation_errors.py index 6c5e0ed254..debb1b6dbf 100644 --- a/src/ecalc/libraries/libecalc/common/libecalc/input/validation_errors.py +++ b/src/ecalc/libraries/libecalc/common/libecalc/input/validation_errors.py @@ -7,6 +7,7 @@ import yaml from libecalc.common.logger import logger from libecalc.input.yaml_entities import Resource, YamlDict, YamlList +from libecalc.input.yaml_keywords import EcalcYamlKeywords from yaml import Dumper, Mark Loc = Tuple[Union[int, str], ...] @@ -126,7 +127,10 @@ def __init__( error_location_info = " -> ".join( [str(s).capitalize().replace("__root__", "General error").replace("_", " ") for s in error_loc] ) - messages.append(f"{error_location_info}:\n\t{error_message}\n") + if component_name := data.get(EcalcYamlKeywords.name): + messages.append(f"{component_name} - {error_location_info}:\n\t{error_message}\n") + else: + messages.append(f"{error_location_info}:\n\t{error_message}\n") except Exception as e: logger.debug(f"Failed to add location specific error messages: {str(e)}")