diff --git a/openlp/core/common/settings.py b/openlp/core/common/settings.py index 624179826..abbf09ec3 100644 --- a/openlp/core/common/settings.py +++ b/openlp/core/common/settings.py @@ -431,14 +431,10 @@ class Settings(QtCore.QSettings): :param key: The key to return the value from. """ # if group() is not empty the group has not been specified together with the key. - try: - if self.group(): - default_value = Settings.__default_settings__[self.group() + '/' + key] - else: - default_value = Settings.__default_settings__[key] - except KeyError: - log.warning('Key "%s" was not found in settings, returning None!' % key) - return None + if self.group(): + default_value = Settings.__default_settings__[self.group() + '/' + key] + else: + default_value = Settings.__default_settings__[key] setting = super(Settings, self).value(key, default_value) return self._convert_value(setting, default_value) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 33e1f6bc7..35d05620a 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -978,7 +978,14 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): # FIXME: We are conflicting with the standard "General" section. if 'eneral' in section_key: section_key = section_key.lower() - key_value = settings.value(section_key) + try: + key_value = settings.value(section_key) + except KeyError: + QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'), + translate('OpenLP.MainWindow', 'The key "%s" does not have a default value ' + 'so it will be skipped in this export.') % section_key, + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) + key_value = None if key_value is not None: export_settings.setValue(section_key, key_value) export_settings.sync() diff --git a/tests/functional/openlp_core_common/test_settings.py b/tests/functional/openlp_core_common/test_settings.py index bcd901a81..e3ce6990d 100644 --- a/tests/functional/openlp_core_common/test_settings.py +++ b/tests/functional/openlp_core_common/test_settings.py @@ -121,9 +121,9 @@ class TestSettings(TestCase, TestMixin): Test the Settings on query for non-existing value """ # GIVEN: A new Settings setup + with self.assertRaises(KeyError) as cm: + # WHEN reading a setting that doesn't exists + does_not_exist_value = Settings().value('core/does not exists') - # WHEN reading a setting that doesn't exists - does_not_exist_value = Settings().value('core/does not exists') - - # THEN None should be returned - self.assertEqual(does_not_exist_value, None, 'The value should be None') + # THEN: An exception with the non-existing key should be thrown + self.assertEqual(str(cm.exception), "'core/does not exists'", 'We should get an exception')