diff --git a/qutebrowser/completion/models/configmodel.py b/qutebrowser/completion/models/configmodel.py index 78ec53338..7b6f7d3b6 100644 --- a/qutebrowser/completion/models/configmodel.py +++ b/qutebrowser/completion/models/configmodel.py @@ -21,7 +21,7 @@ from qutebrowser.config import configdata, configexc from qutebrowser.completion.models import completionmodel, listcategory, util -from qutebrowser.commands import runners +from qutebrowser.commands import runners, cmdexc def option(*, info): @@ -72,8 +72,12 @@ def bind(key, *, info): if cmd_text: parser = runners.CommandParser() - cmd = parser.parse(cmd_text).cmd - data = [(cmd_text, cmd.desc, key)] + try: + cmd = parser.parse(cmd_text).cmd + except cmdexc.NoSuchCommandError: + data = [(cmd_text, 'Invalid command!', key)] + else: + data = [(cmd_text, cmd.desc, key)] model.add_category(listcategory.ListCategory("Current", data)) cmdlist = util.get_cmd_completions(info, include_hidden=True, diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 4e65254c9..30241b1b3 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -119,6 +119,7 @@ def configdata_stub(monkeypatch, configdata_init): 'normal': collections.OrderedDict([ ('', 'quit'), ('ZQ', 'quit'), + ('I', 'invalid'), ]) }, backends=[], @@ -538,7 +539,8 @@ def test_setting_option_completion(qtmodeltester, config_stub, "Options": [ ('aliases', 'Aliases for commands.', '{"q": "quit"}'), ('bindings.commands', 'Default keybindings', - '{"normal": {"": "quit", "ZQ": "quit"}}'), + '{"normal": {"": "quit", "ZQ": "quit", ' + '"I": "invalid"}}'), ('bindings.default', 'Default keybindings', '{"normal": {"": "quit"}}'), ] @@ -573,6 +575,25 @@ def test_bind_completion(qtmodeltester, cmdutils_stub, config_stub, }) +def test_bind_completion_invalid(cmdutils_stub, config_stub, key_config_stub, + configdata_stub, info): + """Test command completion with an invalid command bound.""" + model = configmodel.bind('I', info=info) + model.set_pattern('') + + _check_completions(model, { + "Current": [ + ('invalid', 'Invalid command!', 'I'), + ], + "Commands": [ + ('open', 'open a url', ''), + ('q', "Alias for 'quit'", ''), + ('quit', 'quit qutebrowser', 'ZQ, '), + ('scroll', 'Scroll the current tab in the given direction.', '') + ], + }) + + def test_bind_completion_no_current(qtmodeltester, cmdutils_stub, config_stub, key_config_stub, configdata_stub, info): """Test keybinding completion with no current binding."""