diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 400816656..77b5190ce 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -182,12 +182,12 @@ class YamlConfig(QObject): def _validate(self): """Make sure all settings exist.""" - for name in self._values: - if name not in configdata.DATA: - desc = configexc.ConfigErrorDesc( - "While loading options", - "Unknown option {}".format(name)) - raise configexc.ConfigFileErrors('autoconfig.yml', [desc]) + unknown = set(self._values) - set(configdata.DATA) + if unknown: + errors = [configexc.ConfigErrorDesc("While loading options", + "Unknown option {}".format(e)) + for e in sorted(unknown)] + raise configexc.ConfigFileErrors('autoconfig.yml', errors) def unset(self, name): """Remove the given option name if it's configured.""" diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index d2f37ec25..63f6fbd3f 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -127,6 +127,20 @@ class TestYaml: assert error.text == "While loading options" assert str(error.exception) == "Unknown option hello" + def test_multiple_unknown_keys(self, yaml, config_tmpdir): + """With multiple unknown settings, all should be shown.""" + autoconfig = config_tmpdir / 'autoconfig.yml' + autoconfig.write_text('global:\n one: 1\n two: 2', encoding='utf-8') + + with pytest.raises(configexc.ConfigFileErrors) as excinfo: + yaml.load() + + assert len(excinfo.value.errors) == 2 + error1, error2 = excinfo.value.errors + assert error1.text == error2.text == "While loading options" + assert str(error1.exception) == "Unknown option one" + assert str(error2.exception) == "Unknown option two" + def test_deleted_key(self, monkeypatch, yaml, config_tmpdir): """A key marked as deleted should be removed.""" autoconfig = config_tmpdir / 'autoconfig.yml'