From 63fbd2069203a96a28f066689e8668336d2f3cd1 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 11 Mar 2024 14:42:22 -0700 Subject: [PATCH] actions: Provide HTML error message with action error Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/actions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plinth/actions.py b/plinth/actions.py index eb5908d5e..3db73e26c 100644 --- a/plinth/actions.py +++ b/plinth/actions.py @@ -155,6 +155,19 @@ def _wait_for_return(module_name, action_name, args, kwargs, log_error, proc, exception.stdout = stdout exception.stderr = stderr + def _get_html_message(): + """Return an HTML format error that can be shown in messages.""" + from django.utils.html import format_html + + full_args, exception_args, stdout, stderr, traceback = _format_error( + args, kwargs, exception, return_value) + return format_html('Error running action: {}..{}({}): {}({})\n{}{}{}', + module_name, action_name, full_args, + return_value['exception']['name'], exception_args, + stdout, stderr, traceback) + + exception.get_html_message = _get_html_message + if log_error: full_args, exception_args, stdout, stderr, traceback = _format_error( args, kwargs, exception, return_value)