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.
This commit is contained in:
Fabio Manganiello 2023-07-14 22:15:47 +02:00
parent 27cf1bec52
commit cb04af0bbd
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -15,6 +15,7 @@ from platypush.message.response import Response
from platypush.utils import get_decorators, get_plugin_name_by_class from platypush.utils import get_decorators, get_plugin_name_by_class
PLUGIN_STOP_TIMEOUT = 5 # Plugin stop timeout in seconds PLUGIN_STOP_TIMEOUT = 5 # Plugin stop timeout in seconds
logger = logging.getLogger(__name__)
def action(f: Callable[..., Any]) -> Callable[..., Response]: def action(f: Callable[..., Any]) -> Callable[..., Response]:
@ -29,7 +30,11 @@ def action(f: Callable[..., Any]) -> Callable[..., Response]:
@wraps(f) @wraps(f)
def _execute_action(*args, **kwargs) -> Response: def _execute_action(*args, **kwargs) -> Response:
response = Response() response = Response()
try:
result = f(*args, **kwargs) result = f(*args, **kwargs)
except TypeError as e:
logger.exception(e)
result = Response(errors=[str(e)])
if result and isinstance(result, Response): if result and isinstance(result, Response):
result.errors = ( result.errors = (