From 2c93049ee571ad40942a399fe899d359e5053ad5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 14 Sep 2023 23:08:23 +0200 Subject: [PATCH] Catch all the exceptions in a plugin action wrapper. The @action decorator should capture all the exceptions, log them and return them on `Response.errors`. This ensures that uncaught exceptions from plugin actions won't unwind out of control, and also that they are logged and treated consistently across all the integrations. --- platypush/plugins/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/__init__.py b/platypush/plugins/__init__.py index b0090f60..b5330865 100644 --- a/platypush/plugins/__init__.py +++ b/platypush/plugins/__init__.py @@ -32,7 +32,10 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]: response = Response() try: result = f(*args, **kwargs) - except TypeError as e: + except Exception as e: + if isinstance(e, KeyboardInterrupt): + return response + _logger.exception(e) result = Response(errors=[str(e)])