From 6f39aa6c020a39c1abf40c90652263eb13445543 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Thu, 11 Jul 2024 15:41:42 +0200 Subject: [PATCH] Better description of config syntax error When there is an issue with syntax in avocado config file avocado won't provide enough information for the user to understand the problem. This commit will improve the error message by specifying the wrong value and the reason for syntax error. before this commit: ``` SyntaxError: Syntax error in config file ./pom_config, please check the value /build/avocado/data/cache ``` after this commit: ``` ValueError: /build/avocado/data/cache could not be converted into a list During handling of the above exception, another exception occurred: SyntaxError: Syntax error in config file ./pom_config, please check the value /build/avocado/data/cache ``` Reference: #5906 Signed-off-by: Jan Richter --- avocado/core/settings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/avocado/core/settings.py b/avocado/core/settings.py index 46b2ebb894..7be0fe7ad0 100644 --- a/avocado/core/settings.py +++ b/avocado/core/settings.py @@ -222,7 +222,10 @@ def _as_list(value): return [] if isinstance(value, str): - return ast.literal_eval(value) + try: + return ast.literal_eval(value) + except SyntaxError: + pass if isinstance(value, list): return value @@ -628,7 +631,7 @@ def merge_with_configs(self): value = value[0] try: self.update_option(namespace, value, convert=True) - except SyntaxError: + except (SyntaxError, ValueError): raise SyntaxError( f"Syntax error in config file {path}, please check the value {value} " )