From 6147afe35ff6c700e787e1032114db819cc2fb11 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 18 May 2022 16:54:57 +1000 Subject: [PATCH] Catch errors when rendering custom plugin panels --- InvenTree/plugin/views.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/InvenTree/plugin/views.py b/InvenTree/plugin/views.py index ee855094cc..d03c28bf90 100644 --- a/InvenTree/plugin/views.py +++ b/InvenTree/plugin/views.py @@ -1,5 +1,10 @@ +import sys +import traceback from django.conf import settings +from django.views.debug import ExceptionReporter + +from error_report.models import Error from plugin.registry import registry @@ -21,7 +26,21 @@ class InvenTreePluginViewMixin: panels = [] for plug in registry.with_mixin('panel'): - panels += plug.render_panels(self, self.request, ctx) + + try: + panels += plug.render_panels(self, self.request, ctx) + except Exception as exc: + # Prevent any plugin error from crashing the page render + kind, info, data = sys.exc_info() + + # Log the error to the database + Error.objects.create( + kind=kind.__name__, + info=info, + data='\n'.join(traceback.format_exception(kind, info, data)), + path=self.request.path, + html=ExceptionReporter(self.request, kind, info, data).get_traceback_html(), + ) return panels