Improve error messages with backend conditionals
This commit is contained in:
parent
2f97a597a4
commit
6faff11243
@ -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
|
||||
~~~~~~~
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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!"
|
||||
|
Loading…
Reference in New Issue
Block a user