From 96f28c6f724b81a900ae4c849ba489e3e4e29f6d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 30 Sep 2018 11:45:59 +0200 Subject: Show errors on invalid --mode argument for :hint --- doc/changelog.asciidoc | 1 + qutebrowser/browser/hints.py | 8 +++++++- tests/end2end/features/hints.feature | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index 70274a591..1e554452b 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -93,6 +93,7 @@ Fixed be shown for more files such as `qute://help/userscripts.html`. - Crash when doing initial run on Wayland without XWayland - Crash when trying to load an empty session file. +- `:hint` with an invalid `--mode=` value now shows a proper error. Removed ~~~~~~~ diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 00481c2f4..333999356 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -32,7 +32,7 @@ import attr from PyQt5.QtCore import pyqtSlot, QObject, Qt, QUrl from PyQt5.QtWidgets import QLabel -from qutebrowser.config import config +from qutebrowser.config import config, configexc from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.browser import webelem from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners @@ -726,6 +726,12 @@ class HintManager(QObject): if mode is None: mode = config.val.hints.mode + else: + opt = config.instance.get_opt('hints.mode') + try: + opt.typ.to_py(mode) + except configexc.ValidationError as e: + raise cmdexc.CommandError("Invalid mode: {}".format(e)) self._check_args(target, *args) self._context = HintContext() diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature index 3a0cb1da0..fd4465daa 100644 --- a/tests/end2end/features/hints.feature +++ b/tests/end2end/features/hints.feature @@ -15,6 +15,10 @@ Feature: Using hints And I hint with args "links normal" and follow xyz Then the error "No hint xyz!" should be shown + Scenario: Using :hint with invalid mode. + When I run :hint --mode=foobar + Then the error "Invalid mode: Invalid value 'foobar' - valid values: number, letter, word" should be shown + ### Opening in current or new tab Scenario: Following a hint and force to open in current tab. -- cgit v1.2.3-54-g00ecf