mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 03:00:54 +00:00
Tweak plugin load error messages (#9839)
* Tweak plugin load error messages * Update unit tests
This commit is contained in:
@ -603,7 +603,7 @@ class PluginsRegistry:
|
||||
raise e
|
||||
except Exception as error:
|
||||
handle_error(
|
||||
error, log_name='init'
|
||||
error, log_name=f'{plg_name}:init_plugin'
|
||||
) # log error and raise it -> disable plugin
|
||||
|
||||
logger.warning('Plugin `%s` could not be loaded', plg_name)
|
||||
@ -629,7 +629,7 @@ class PluginsRegistry:
|
||||
if v := plg_i.MAX_VERSION:
|
||||
_msg += _(f'Plugin requires at most version {v}')
|
||||
# Log to error stack
|
||||
log_error(_msg, reference='init')
|
||||
log_error(_msg, reference=f'{p}:init_plugin')
|
||||
else:
|
||||
safe_reference(plugin=plg_i, key=plg_key)
|
||||
else: # pragma: no cover
|
||||
@ -666,7 +666,7 @@ class PluginsRegistry:
|
||||
except Exception as error:
|
||||
# Handle the error, log it and try again
|
||||
if attempts == 0:
|
||||
handle_error(error, log_name='init', do_raise=True)
|
||||
handle_error(error, log_name='init_plugins', do_raise=True)
|
||||
|
||||
logger.exception(
|
||||
'[PLUGIN] Encountered an error with %s:\n%s',
|
||||
|
@ -280,7 +280,7 @@ class RegistryTests(TestCase):
|
||||
# Reload to rediscover plugins
|
||||
registry.reload_plugins(full_reload=True, collect=True)
|
||||
|
||||
self.assertEqual(len(registry.errors), 2)
|
||||
self.assertEqual(len(registry.errors), 3)
|
||||
|
||||
# There should be at least one discovery error in the module `broken_file`
|
||||
self.assertGreater(len(registry.errors.get('discovery')), 0)
|
||||
@ -290,9 +290,10 @@ class RegistryTests(TestCase):
|
||||
)
|
||||
|
||||
# There should be at least one load error with an intentional KeyError
|
||||
self.assertGreater(len(registry.errors.get('init')), 0)
|
||||
self.assertGreater(len(registry.errors.get('Test:init_plugin')), 0)
|
||||
self.assertEqual(
|
||||
registry.errors.get('init')[0]['broken_sample'], "'This is a dummy error'"
|
||||
registry.errors.get('Test:init_plugin')[0]['broken_sample'],
|
||||
"'This is a dummy error'",
|
||||
)
|
||||
|
||||
@override_settings(PLUGIN_TESTING=True, PLUGIN_TESTING_SETUP=True)
|
||||
|
Reference in New Issue
Block a user