diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index 17814be68..7b8f4b207 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -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,17 +300,20 @@ class RegisterKeyParser(keyparser.BaseKeyParser): window=self._win_id) macro_recorder = objreg.get('macro-recorder') - if self._mode == usertypes.KeyMode.set_mark: - tabbed_browser.set_mark(key) - elif self._mode == usertypes.KeyMode.jump_mark: - tabbed_browser.jump_mark(key) - elif self._mode == usertypes.KeyMode.record_macro: - macro_recorder.record_macro(key) - elif self._mode == usertypes.KeyMode.run_macro: - macro_recorder.run_macro(self._win_id, key) - else: - raise ValueError( - "{} is not a valid register key".format(self._mode)) + try: + if self._mode == usertypes.KeyMode.set_mark: + tabbed_browser.set_mark(key) + elif self._mode == usertypes.KeyMode.jump_mark: + tabbed_browser.jump_mark(key) + elif self._mode == usertypes.KeyMode.record_macro: + macro_recorder.record_macro(key) + elif self._mode == usertypes.KeyMode.run_macro: + macro_recorder.run_macro(self._win_id, key) + 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") diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 0727f97cb..e66cfc94b 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -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