2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-11 06:10:54 +00:00

feat(backend): more error messages (#10119)

* Adds error code for transition handler issues #10088

* Adds error codes for mandatory plugins #10094

* add more links

* Add error code  for global overrides

* disable coverage for a case that can not happen
This commit is contained in:
Matthias Mair
2025-08-04 02:06:13 +02:00
committed by GitHub
parent bdc8525aec
commit b8f6b04fb9
8 changed files with 49 additions and 12 deletions

View File

@@ -1438,7 +1438,9 @@ if SITE_URL:
GLOBAL_SETTINGS_OVERRIDES['INVENTREE_BASE_URL'] = SITE_URL
if len(GLOBAL_SETTINGS_OVERRIDES) > 0:
logger.info('Global settings overrides: %s', str(GLOBAL_SETTINGS_OVERRIDES))
logger.info(
'INVE-I1: Global settings overrides: %s', str(GLOBAL_SETTINGS_OVERRIDES)
)
for key in GLOBAL_SETTINGS_OVERRIDES:
# Set the global setting
logger.debug('- Override value for %s = ********', key)

View File

@@ -56,7 +56,9 @@ class CommonConfig(AppConfig):
if current_value != value:
logger.info(
'Overriding global setting: %s = %s', value, current_value
'INVE-I1: Overriding global setting: %s = %s',
value,
current_value,
)
set_global_setting(key, value, None, create=True)

View File

@@ -107,14 +107,16 @@ class StateTransitionMixin:
if type(handlers) is not list:
logger.error(
'Plugin %s returned invalid type for transition handlers',
'INVE-E9: Plugin %s returned invalid type for transition handlers',
plugin.slug,
)
continue
for handler in handlers:
if not isinstance(handler, TransitionMethod):
logger.error('Invalid transition handler type: %s', handler)
logger.error(
'INVE-E9: Invalid transition handler type: %s', handler
)
continue
# Call the transition method

View File

@@ -48,14 +48,14 @@ class TransitionMixin:
if not isinstance(handlers, list):
raise TypeError(
'TRANSITION_HANDLERS must be a list of TransitionMethod instances'
'INVE-E9: TRANSITION_HANDLERS must be a list of TransitionMethod instances'
)
handler_methods = []
for handler in handlers:
if not isinstance(handler, TransitionMethod):
logger.error('Invalid transition handler type: %s', handler)
logger.error('INVE-E9: Invalid transition handler type: %s', handler)
continue
handler_methods.append(handler)

View File

@@ -341,17 +341,20 @@ def uninstall_plugin(cfg: plugin.models.PluginConfig, user=None, delete_config=T
_('Plugin cannot be uninstalled as it is currently active')
)
if cfg.is_mandatory():
raise ValidationError(_('Plugin cannot be uninstalled as it is mandatory'))
if cfg.is_mandatory(): # pragma: no cover
# This is only an additional check, as mandatory plugins cannot be deactivated
raise ValidationError(
'INVE-E10' + _('Plugin cannot be uninstalled as it is mandatory')
)
if cfg.is_sample():
raise ValidationError(
_('Plugin cannot be uninstalled as it is a sample plugin')
'INVE-E10' + _('Plugin cannot be uninstalled as it is a sample plugin')
)
if cfg.is_builtin():
raise ValidationError(
_('Plugin cannot be uninstalled as it is a built-in plugin')
'INVE-E10' + _('Plugin cannot be uninstalled as it is a built-in plugin')
)
if not cfg.is_installed():

View File

@@ -332,7 +332,8 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
for name in child_methods:
if name in final_methods:
raise TypeError(
f"Plugin '{cls.__name__}' cannot override final method '{name}' from InvenTreePlugin."
'INVE-E11: '
+ f"Plugin '{cls.__name__}' cannot override final method '{name}' from InvenTreePlugin."
)
return super().__init_subclass__()

View File

@@ -239,7 +239,9 @@ class PluginActivateSerializer(serializers.Serializer):
active = validated_data.get('active', True)
if not active and instance.is_mandatory():
raise ValidationError(_('Mandatory plugin cannot be deactivated'))
raise ValidationError(
'INVE-E10: ' + _('Mandatory plugin cannot be deactivated')
)
instance.activate(active)
return instance