2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-07 12:22:11 +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

@@ -50,6 +50,25 @@ This might be caused by an addition or removal of models to the code base or cha
The settings for SITE_URL and ALLOWED_HOSTS do not match the host used to access the server. This might lead to issues with CSRF protection, CORS and other security features. The settings for SITE_URL and ALLOWED_HOSTS do not match the host used to access the server. This might lead to issues with CSRF protection, CORS and other security features.
The settings must be adjusted. The settings must be adjusted.
#### INVE-E9
**Transition handler error - Backend**
An error occurred while discovering or executing a transition handler. This likely indicates a faulty or incompatible plugin.
This error is raised by a plugin with the `TransitionMixin` and can be debugged by looking into the logs for more information.
#### INVE-E10
**Plugin cannot be uninstalled or deactivated - Backend**
A plugin cannot be uninstalled if it is mandatory, a sample or a built-in plugin. Mandatory plugins can not be deactivated.
This is to prevent accidental removal of essential system or compliance functionality. If you want to remove/deactivate a mandatory plugin, you need to remove it from the `INVENTREE_PLUGINS_MANDATORY` [setting](../start/config.md#plugin-options). Sample and built-in plugins can not be uninstalled at all but might be deactivated.
See [Mandatory Plugins](../plugins/index.md#mandatory-plugins) for more information.
#### INVE-E11
**Plugin cannot override final method - Backend**
A plugin is not allowed to override a *final method* from the `InvenTreePlugin` class.
This is a security measure to prevent plugins from changing the core functionality of InvenTree. The code of the plugin must be changed to not override functions that are marked as *final*.
### INVE-W (InvenTree Warning) ### INVE-W (InvenTree Warning)
Warnings - These are non-critical errors which should be addressed when possible. Warnings - These are non-critical errors which should be addressed when possible.
@@ -144,5 +163,11 @@ To enable registration, the email settings must be configured correctly. See [e
### INVE-I (InvenTree Information) ### INVE-I (InvenTree Information)
Information — These are not errors but information messages. They might point out potential issues or just provide information. Information — These are not errors but information messages. They might point out potential issues or just provide information.
#### INVE-I1
**Setting overridden - Backend**
Overriding a global setting with a different value than the current one.
See [Override global settings](../settings/global.md#override-global-settings) for more information.
### INVE-M (InvenTree Miscellaneous) ### INVE-M (InvenTree Miscellaneous)
Miscellaneous — These are information messages that might be used to mark debug information or other messages helpful for the InvenTree team to understand behaviour. Miscellaneous — These are information messages that might be used to mark debug information or other messages helpful for the InvenTree team to understand behaviour.

View File

@@ -1438,7 +1438,9 @@ if SITE_URL:
GLOBAL_SETTINGS_OVERRIDES['INVENTREE_BASE_URL'] = SITE_URL GLOBAL_SETTINGS_OVERRIDES['INVENTREE_BASE_URL'] = SITE_URL
if len(GLOBAL_SETTINGS_OVERRIDES) > 0: 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: for key in GLOBAL_SETTINGS_OVERRIDES:
# Set the global setting # Set the global setting
logger.debug('- Override value for %s = ********', key) logger.debug('- Override value for %s = ********', key)

View File

@@ -56,7 +56,9 @@ class CommonConfig(AppConfig):
if current_value != value: if current_value != value:
logger.info( 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) set_global_setting(key, value, None, create=True)

View File

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

View File

@@ -48,14 +48,14 @@ class TransitionMixin:
if not isinstance(handlers, list): if not isinstance(handlers, list):
raise TypeError( raise TypeError(
'TRANSITION_HANDLERS must be a list of TransitionMethod instances' 'INVE-E9: TRANSITION_HANDLERS must be a list of TransitionMethod instances'
) )
handler_methods = [] handler_methods = []
for handler in handlers: for handler in handlers:
if not isinstance(handler, TransitionMethod): if not isinstance(handler, TransitionMethod):
logger.error('Invalid transition handler type: %s', handler) logger.error('INVE-E9: Invalid transition handler type: %s', handler)
continue continue
handler_methods.append(handler) 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') _('Plugin cannot be uninstalled as it is currently active')
) )
if cfg.is_mandatory(): if cfg.is_mandatory(): # pragma: no cover
raise ValidationError(_('Plugin cannot be uninstalled as it is mandatory')) # 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(): if cfg.is_sample():
raise ValidationError( 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(): if cfg.is_builtin():
raise ValidationError( 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(): if not cfg.is_installed():

View File

@@ -332,7 +332,8 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
for name in child_methods: for name in child_methods:
if name in final_methods: if name in final_methods:
raise TypeError( 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__() return super().__init_subclass__()

View File

@@ -239,7 +239,9 @@ class PluginActivateSerializer(serializers.Serializer):
active = validated_data.get('active', True) active = validated_data.get('active', True)
if not active and instance.is_mandatory(): 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) instance.activate(active)
return instance return instance