summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-08-15 18:14:12 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-08-15 18:39:22 +0200
commitdc2a988f92623c401eb8d0b12260ed395a79961f (patch)
treee0f6f75e3727377826296916ec9e9e9702b83b5b
parent89b3e1bbf214bcc7419b379eb984d1353e684ed2 (diff)
downloadqutebrowser-dc2a988f92623c401eb8d0b12260ed395a79961f.tar.gz
qutebrowser-dc2a988f92623c401eb8d0b12260ed395a79961f.zip
config: Handle config.py errors while updating mutables
Fixes #3580 (cherry picked from commit d9e20f6b3071b86b479f281fe27d621e0b3ae7e5)
-rw-r--r--qutebrowser/config/configfiles.py4
-rw-r--r--tests/unit/config/test_configcommands.py13
-rw-r--r--tests/unit/config/test_configfiles.py9
3 files changed, 25 insertions, 1 deletions
diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py
index ca580102f..f14e0c1fa 100644
--- a/qutebrowser/config/configfiles.py
+++ b/qutebrowser/config/configfiles.py
@@ -674,7 +674,9 @@ class ConfigAPI:
" (to load settings configured via the GUI) or "
"`config.load_autoconfig(False)` (to not do so)"))
self.errors.append(desc)
- self._config.update_mutables()
+
+ with self._handle_error("updating mutated values"):
+ self._config.update_mutables()
def load_autoconfig(self, load_config: bool = True) -> None:
"""Load the autoconfig.yml file which is used for :set/:bind/etc."""
diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py
index d7031de94..22de04070 100644
--- a/tests/unit/config/test_configcommands.py
+++ b/tests/unit/config/test_configcommands.py
@@ -587,6 +587,19 @@ class TestSource:
" division by zero")
assert str(excinfo.value) == expected
+ def test_invalid_mutable(self, commands, config_tmpdir):
+ pyfile = config_tmpdir / 'config.py'
+ src = 'c.url.searchengines["maps"] = "https://www.google.com/maps?q=%s"'
+ pyfile.write_text(src, encoding="utf-8")
+
+ with pytest.raises(cmdutils.CommandError) as excinfo:
+ commands.config_source()
+
+ err = "Invalid value 'https://www.google.com/maps?q=%s' - must contain \"{}\""
+ expected = ("Errors occurred while reading config.py:\n"
+ f" While updating mutated values: {err}")
+ assert str(excinfo.value) == expected
+
class TestEdit:
diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py
index 760992e15..00bc8a806 100644
--- a/tests/unit/config/test_configfiles.py
+++ b/tests/unit/config/test_configfiles.py
@@ -1060,6 +1060,15 @@ class TestConfigPy:
assert config.instance.get_obj('aliases')['foo'] == 'message-info foo'
assert config.instance.get_obj('aliases')['bar'] == 'message-info bar'
+ def test_mutating_invalid_value(self, confpy):
+ confpy.write('c.url.searchengines["maps"] = "https://www.google.com/maps?q=%s"')
+ error = confpy.read(error=True)
+
+ assert error.text == "While updating mutated values"
+ assert isinstance(error.exception, configexc.ValidationError)
+
+ assert 'maps' not in config.instance.get_obj("url.searchengines")
+
@pytest.mark.parametrize('option, value', [
('content.user_stylesheets', 'style.css'),
('url.start_pages', 'https://www.python.org/'),