From 4566ddd9ae2b9619b046d4686d13e30c09ff8dfd Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Mon, 11 May 2015 21:29:03 +0200 Subject: [PATCH] ext: Add exception logging to extension loading --- mopidy/ext.py | 19 +++++++------------ tests/test_ext.py | 6 +----- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/mopidy/ext.py b/mopidy/ext.py index a59eeae1..96e5d5e1 100644 --- a/mopidy/ext.py +++ b/mopidy/ext.py @@ -155,32 +155,27 @@ def load_extensions(): logger.debug('Loading entry point: %s', entry_point) extension_class = entry_point.load(require=False) - # TODO: start using _extension_error_handling(...) pattern - try: if not issubclass(extension_class, Extension): - continue # TODO: log this + raise TypeError # issubclass raises TypeError on non-class 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: extension = extension_class() config_schema = extension.get_config_schema() default_config = extension.get_default_config() - except Exception: - continue # TODO: log this - - try: command = extension.get_command() 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( extension, entry_point, config_schema, default_config, command)) - # TODO: call validate_extension here? - # TODO: do basic config tests like schema contains enabled? - logger.debug( 'Loaded extension: %s %s', extension.dist_name, extension.version) diff --git a/tests/test_ext.py b/tests/test_ext.py index f6f31c21..b4fa8b9e 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -154,13 +154,9 @@ def test_load_extensions_get_command_fails(iter_entry_points_mock): 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: get_command.side_effect = Exception - assert [expected] == ext.load_extensions() + assert [] == ext.load_extensions() get_command.assert_called_once_with()