From cb04af0bbd5593ba0282e9743c7bc452e92da56d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 14 Jul 2023 22:15:47 +0200 Subject: [PATCH] Catch TypeError when execution an action. Most of TypeError are due to the user passing wrong data. It usually doesn't mean that we have to fail hard and reload the plugin, nor retry the call with the same parameters. --- platypush/plugins/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/__init__.py b/platypush/plugins/__init__.py index 22bd04abd..a66a7e34e 100644 --- a/platypush/plugins/__init__.py +++ b/platypush/plugins/__init__.py @@ -15,6 +15,7 @@ from platypush.message.response import Response from platypush.utils import get_decorators, get_plugin_name_by_class PLUGIN_STOP_TIMEOUT = 5 # Plugin stop timeout in seconds +logger = logging.getLogger(__name__) def action(f: Callable[..., Any]) -> Callable[..., Response]: @@ -29,7 +30,11 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]: @wraps(f) def _execute_action(*args, **kwargs) -> Response: response = Response() - result = f(*args, **kwargs) + try: + result = f(*args, **kwargs) + except TypeError as e: + logger.exception(e) + result = Response(errors=[str(e)]) if result and isinstance(result, Response): result.errors = (