ext: Add exception logging to extension loading
This commit is contained in:
parent
8ed9e5f1e0
commit
4566ddd9ae
@ -155,32 +155,27 @@ def load_extensions():
|
|||||||
logger.debug('Loading entry point: %s', entry_point)
|
logger.debug('Loading entry point: %s', entry_point)
|
||||||
extension_class = entry_point.load(require=False)
|
extension_class = entry_point.load(require=False)
|
||||||
|
|
||||||
# TODO: start using _extension_error_handling(...) pattern
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not issubclass(extension_class, Extension):
|
if not issubclass(extension_class, Extension):
|
||||||
continue # TODO: log this
|
raise TypeError # issubclass raises TypeError on non-class
|
||||||
except TypeError:
|
except TypeError:
|
||||||
continue # TODO: log that extension_class is not a class
|
logger.error('Entry point %s did not contain a valid extension'
|
||||||
|
'class: %r', entry_point.name, extension_class)
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
extension = extension_class()
|
extension = extension_class()
|
||||||
config_schema = extension.get_config_schema()
|
config_schema = extension.get_config_schema()
|
||||||
default_config = extension.get_default_config()
|
default_config = extension.get_default_config()
|
||||||
except Exception:
|
|
||||||
continue # TODO: log this
|
|
||||||
|
|
||||||
try:
|
|
||||||
command = extension.get_command()
|
command = extension.get_command()
|
||||||
except Exception:
|
except Exception:
|
||||||
command = None # TODO: log this.
|
logger.exception('Setup of extension from entry point %s failed, '
|
||||||
|
'ignoring extension.', entry_point.name)
|
||||||
|
continue
|
||||||
|
|
||||||
installed_extensions.append(ExtensionData(
|
installed_extensions.append(ExtensionData(
|
||||||
extension, entry_point, config_schema, default_config, command))
|
extension, entry_point, config_schema, default_config, command))
|
||||||
|
|
||||||
# TODO: call validate_extension here?
|
|
||||||
# TODO: do basic config tests like schema contains enabled?
|
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Loaded extension: %s %s', extension.dist_name, extension.version)
|
'Loaded extension: %s %s', extension.dist_name, extension.version)
|
||||||
|
|
||||||
|
|||||||
@ -154,13 +154,9 @@ def test_load_extensions_get_command_fails(iter_entry_points_mock):
|
|||||||
|
|
||||||
iter_entry_points_mock.return_value = [mock_entry_point]
|
iter_entry_points_mock.return_value = [mock_entry_point]
|
||||||
|
|
||||||
expected = ext.ExtensionData(
|
|
||||||
any_testextension, mock_entry_point, IsA(config.ConfigSchema),
|
|
||||||
any_unicode, None)
|
|
||||||
|
|
||||||
with mock.patch.object(TestExtension, 'get_command') as get_command:
|
with mock.patch.object(TestExtension, 'get_command') as get_command:
|
||||||
get_command.side_effect = Exception
|
get_command.side_effect = Exception
|
||||||
assert [expected] == ext.load_extensions()
|
assert [] == ext.load_extensions()
|
||||||
get_command.assert_called_once_with()
|
get_command.assert_called_once_with()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user