Catch RegisterKeyParser command errors

This commit is contained in:
Jan Verbeek 2016-10-20 17:37:02 +02:00
parent f2b05a0395
commit 21289a80ad
2 changed files with 33 additions and 12 deletions

View File

@ -23,11 +23,14 @@ Module attributes:
STARTCHARS: Possible chars for starting a commandline input.
"""
import traceback
from PyQt5.QtCore import pyqtSlot, Qt
from qutebrowser.commands import cmdexc
from qutebrowser.config import config
from qutebrowser.keyinput import keyparser
from qutebrowser.utils import usertypes, log, objreg, utils
from qutebrowser.utils import usertypes, log, message, objreg, utils
STARTCHARS = ":/?"
@ -297,6 +300,7 @@ class RegisterKeyParser(keyparser.BaseKeyParser):
window=self._win_id)
macro_recorder = objreg.get('macro-recorder')
try:
if self._mode == usertypes.KeyMode.set_mark:
tabbed_browser.set_mark(key)
elif self._mode == usertypes.KeyMode.jump_mark:
@ -308,6 +312,8 @@ class RegisterKeyParser(keyparser.BaseKeyParser):
else:
raise ValueError(
"{} is not a valid register key".format(self._mode))
except (cmdexc.CommandMetaError, cmdexc.CommandError) as err:
message.error(str(err), stack=traceback.format_exc())
self.request_leave.emit(self._mode, "valid register key")

View File

@ -648,6 +648,21 @@ Feature: Various utility commands.
And I run :run-macro foo with count 2
Then the page should not be scrolled
Scenario: Running an invalid macro
Given I open data/scroll/simple.html
And I run :tab-only
When I run :run-macro
And I press the key "b"
Then the error "No macro recorded in 'b'!" should be shown
And no crash should happen
Scenario: Running an invalid named macro
Given I open data/scroll/simple.html
And I run :tab-only
When I run :run-macro bar
Then the error "No macro recorded in 'bar'!" should be shown
And no crash should happen
## Variables
Scenario: {url} as part of an argument