From 9e004285680041a407935fe673dd9c95ae177bd6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 26 Feb 2021 22:43:54 +0100 Subject: [PATCH] Don't fail silently if there were errors in parsing ${} variables or getting the context --- platypush/message/request/__init__.py | 6 ++++-- platypush/procedure/__init__.py | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 6ff30dc35e..6737e0eade 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -130,8 +130,10 @@ class Request(Message): if isinstance(v, str): try: exec('{}="{}"'.format(k, re.sub(r'(^|[^\\])"', '\1\\"', v))) - except: - pass + except Exception as e: + logger.warning('Could not set context variable {}={}'.format(k, v)) + logger.warning('Context: {}'.format(json.dumps(context))) + logger.exception(e) parsed_value = '' if not isinstance(_value, str): diff --git a/platypush/procedure/__init__.py b/platypush/procedure/__init__.py index 31ab570f7e..1bea767d9f 100644 --- a/platypush/procedure/__init__.py +++ b/platypush/procedure/__init__.py @@ -1,4 +1,5 @@ import enum +import json import logging import re from functools import wraps @@ -340,8 +341,10 @@ class WhileProcedure(LoopProcedure): # noinspection PyBroadException try: context[k] = eval('"{}"'.format(re.sub(r'(^|[^\\])"', '\1\\"', v))) - except: - pass + except Exception as e: + logger.warning('Could not parse value for context variable {}={}'.format(k, v)) + logger.warning('Context: {}'.format(json.dumps(context))) + logger.exception(e) return context @@ -453,8 +456,10 @@ class IfProcedure(Procedure): if isinstance(v, str): try: exec('{}="{}"'.format(k, re.sub(r'(^|[^\\])"', '\1\\"', v))) - except: - pass + except Exception as e: + logger.warning('Could not set context variable {}={}'.format(k, v)) + logger.warning('Context: {}'.format(json.dumps(context))) + logger.exception(e) condition_true = eval(self.condition) response = Response()