From db4e68e247eea6d150b97883a99f99f268cd021f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 13 Jan 2019 20:09:25 +0100 Subject: [PATCH] Do exception logging at Request level and discard duplicate exception messages between retries --- platypush/message/request/__init__.py | 5 ++++- platypush/plugins/__init__.py | 26 ++++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/platypush/message/request/__init__.py b/platypush/message/request/__init__.py index 174a91fdc..6bf4aa180 100644 --- a/platypush/message/request/__init__.py +++ b/platypush/message/request/__init__.py @@ -215,12 +215,15 @@ class Request(Message): format(plugin, self.action, str(response))) except Exception as e: # Retry mechanism + plugin.logger.exception(e) logger.warning(('Uncaught exception while processing response ' + 'from action {}.{}: {}').format( plugin, self.action, str(e))) errors = errors or [] - errors.append(str(e)) + if str(e) not in errors: + errors.append(str(e)) + response = Response(output=None, errors=errors) if n_tries-1 > 0: logger.info('Reloading plugin {} and retrying'.format(module_name)) diff --git a/platypush/plugins/__init__.py b/platypush/plugins/__init__.py index 22c7f03cc..c6addb3f2 100644 --- a/platypush/plugins/__init__.py +++ b/platypush/plugins/__init__.py @@ -14,23 +14,17 @@ def action(f): output = None errors = [] - try: - output = f(*args, **kwargs) - if output and isinstance(output, Response): - errors = output.errors \ - if isinstance(output.errors, list) else [output.errors] - output = output.output - elif isinstance(output, tuple) and len(output) == 2: - errors = output[1] \ - if isinstance(output[1], list) else [output[1]] + output = f(*args, **kwargs) + if output and isinstance(output, Response): + errors = output.errors \ + if isinstance(output.errors, list) else [output.errors] + output = output.output + elif isinstance(output, tuple) and len(output) == 2: + errors = output[1] \ + if isinstance(output[1], list) else [output[1]] - if len(errors) == 1 and errors[0] is None: errors = [] - output = output[0] - except Exception as e: - if isinstance(args[0], Plugin): - args[0].logger.exception(e) - raise e - # errors.append(str(e) + '\n' + traceback.format_exc()) + if len(errors) == 1 and errors[0] is None: errors = [] + output = output[0] return Response(output=output, errors=errors)