diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index becaae355..c05f2d6b3 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -80,6 +80,7 @@ Changed (e.g. `--logfilter '!init,destroy'`) to invert the filter. - `:view-source` now has a `--pygments` flag which uses the "old" way of rendering sources even with QtWebEngine. +- Improved error messages when a setting needs a newer Qt version. Removed ~~~~~~~ diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 7204fb8f3..d173eb1e0 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -276,7 +276,8 @@ class Config(QObject): """Set the given option to the given value.""" if not isinstance(objects.backend, objects.NoBackend): if objects.backend not in opt.backends: - raise configexc.BackendError(opt.name, objects.backend) + raise configexc.BackendError(opt.name, objects.backend, + opt.raw_backends) opt.typ.to_py(value) # for validation diff --git a/qutebrowser/config/configexc.py b/qutebrowser/config/configexc.py index 4d1ab5d7f..2a99dfa5c 100644 --- a/qutebrowser/config/configexc.py +++ b/qutebrowser/config/configexc.py @@ -44,9 +44,15 @@ class BackendError(Error): """Raised when this setting is unavailable with the current backend.""" - def __init__(self, name, backend): - super().__init__("The {} setting is not available with the {} " - "backend!".format(name, backend.name)) + def __init__(self, name, backend, raw_backends): + if raw_backends is None or not raw_backends[backend.name]: + msg = ("The {} setting is not available with the {} backend!" + .format(name, backend.name)) + else: + msg = ("The {} setting needs {} with the {} backend!" + .format(name, raw_backends[backend.name], backend.name)) + + super().__init__(msg) class NoPatternError(Error): diff --git a/tests/unit/config/test_configexc.py b/tests/unit/config/test_configexc.py index c11850a15..98ab19396 100644 --- a/tests/unit/config/test_configexc.py +++ b/tests/unit/config/test_configexc.py @@ -54,12 +54,23 @@ def test_no_autoconfig_error(): assert str(e) == expected -def test_backend_error(): - e = configexc.BackendError('foo', usertypes.Backend.QtWebKit) +@pytest.mark.parametrize('raw_backends', [ + None, + {'QtWebEngine': 'Qt 5.11', 'QtWebKit': False} +]) +def test_backend_error(raw_backends): + e = configexc.BackendError('foo', usertypes.Backend.QtWebKit, raw_backends) expected = "The foo setting is not available with the QtWebKit backend!" assert str(e) == expected +def test_backend_error_condition(): + e = configexc.BackendError('foo', usertypes.Backend.QtWebEngine, + {'QtWebEngine': 'Qt 5.11', 'QtWebKit': True}) + expected = "The foo setting needs Qt 5.11 with the QtWebEngine backend!" + assert str(e) == expected + + def test_no_pattern_error(): e = configexc.NoPatternError('foo') expected = "The foo setting does not support URL patterns!"