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