diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 046bf2a798..7c51f2da9a 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -97,6 +97,14 @@ class PluginValidationMixin(DiffMixin): return except ValidationError as exc: raise exc + except Exception as exc: + # Log the exception to the database + import InvenTree.exceptions + + InvenTree.exceptions.log_error( + f'plugins.{plugin.slug}.validate_model_instance' + ) + raise ValidationError(_('Error running plugin validation')) def full_clean(self): """Run plugin validation on full model clean. diff --git a/InvenTree/plugin/base/event/events.py b/InvenTree/plugin/base/event/events.py index 28e18f71fe..125d1b17bf 100644 --- a/InvenTree/plugin/base/event/events.py +++ b/InvenTree/plugin/base/event/events.py @@ -7,6 +7,7 @@ from django.db import transaction from django.db.models.signals import post_delete, post_save from django.dispatch.dispatcher import receiver +import InvenTree.exceptions from InvenTree.ready import canAppAccessDatabase, isImportingData from InvenTree.tasks import offload_task from plugin.registry import registry @@ -95,9 +96,16 @@ def process_event(plugin_slug, event, *args, **kwargs): logger.error("Could not find matching plugin for '%s'", plugin_slug) return - plugin.process_event(event, *args, **kwargs) logger.debug("Plugin '%s' is processing triggered event '%s'", plugin_slug, event) + try: + plugin.process_event(event, *args, **kwargs) + except Exception as e: + # Log the exception to the database + InvenTree.exceptions.log_error(f'plugins.{plugin_slug}.process_event') + # Re-throw the exception so that the background worker tries again + raise Exception + def allow_table_event(table_name): """Determine if an automatic event should be fired for a given table. diff --git a/InvenTree/report/models.py b/InvenTree/report/models.py index b8d611acc3..269b38ee6c 100644 --- a/InvenTree/report/models.py +++ b/InvenTree/report/models.py @@ -16,6 +16,7 @@ from django.utils.translation import gettext_lazy as _ import build.models import common.models +import InvenTree.exceptions import InvenTree.models import order.models import part.models @@ -263,7 +264,12 @@ class ReportTemplateBase(MetadataMixin, ReportBase): for plugin in plugins: # Let each plugin add its own context data - plugin.add_report_context(self, self.object_to_print, request, context) + try: + plugin.add_report_context(self, self.object_to_print, request, context) + except Exception: + InvenTree.exceptions.log_error( + f'plugins.{plugin.slug}.add_report_context' + ) return context diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index f4d729eee7..88183da23c 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -25,6 +25,7 @@ from mptt.models import MPTTModel, TreeForeignKey from taggit.managers import TaggableManager import common.models +import InvenTree.exceptions import InvenTree.helpers import InvenTree.models import InvenTree.ready @@ -601,6 +602,10 @@ class StockItem( plugin.validate_batch_code(self.batch, self) except ValidationError as exc: raise ValidationError({'batch': exc.message}) + except Exception: + InvenTree.exceptions.log_error( + f'plugin.{plugin.slug}.validate_batch_code' + ) def clean(self): """Validate the StockItem object (separate to field validation).