mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Merge pull request #3026 from SchrodingersGat/plugin-panel-error-catch
Catch errors when rendering custom plugin panels
This commit is contained in:
		| @@ -1,5 +1,10 @@ | |||||||
|  | import sys | ||||||
|  | import traceback | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
|  | from django.views.debug import ExceptionReporter | ||||||
|  |  | ||||||
|  | from error_report.models import Error | ||||||
|  |  | ||||||
| from plugin.registry import registry | from plugin.registry import registry | ||||||
|  |  | ||||||
| @@ -21,7 +26,21 @@ class InvenTreePluginViewMixin: | |||||||
|         panels = [] |         panels = [] | ||||||
|  |  | ||||||
|         for plug in registry.with_mixin('panel'): |         for plug in registry.with_mixin('panel'): | ||||||
|  |  | ||||||
|  |             try: | ||||||
|                 panels += plug.render_panels(self, self.request, ctx) |                 panels += plug.render_panels(self, self.request, ctx) | ||||||
|  |             except Exception: | ||||||
|  |                 # 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 |         return panels | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user