From 21a29d6c9f66233c9b40d9891c61c69ae82e06cf Mon Sep 17 00:00:00 2001 From: gnikit Date: Sun, 28 Apr 2024 18:00:51 +0100 Subject: [PATCH] refactor: improve error handling in preprocessor IF statement evaluation Now throws fortls exception --- fortls/parsers/internal/parser.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fortls/parsers/internal/parser.py b/fortls/parsers/internal/parser.py index 60f42f97..ae84ce64 100644 --- a/fortls/parsers/internal/parser.py +++ b/fortls/parsers/internal/parser.py @@ -2075,11 +2075,10 @@ def replace_vars(line: str): if defs is None: defs = {} try: - line_res = eval(replace_ops(replace_vars(replace_defined(text)))) - except: - return False - else: - return line_res + return eval(replace_ops(replace_vars(replace_defined(text)))) + except Exception as exc: + log.error("Error evaluating preprocessor IF statement: %s", exc) + raise ParserError(exc) from exc def expand_func_macro(def_name: str, def_value: tuple[str, str]): def_args, sub = def_value