diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 118474611..2f14ddc55 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -631,9 +631,8 @@ class CommandDispatcher: cur = self._tabs.currentWidget() if cur.inspector is None: if not config.get('general', 'developer-extras'): - message.error("Please enable developer-extras before using " - "the webinspector!") - return + raise CommandError("Please enable developer-extras before " + "using the webinspector!") cur.inspector = QWebInspector() cur.inspector.setPage(cur.page()) cur.inspector.show() @@ -641,9 +640,8 @@ class CommandDispatcher: cur.inspector.hide() else: if not config.get('general', 'developer-extras'): - message.error("Please enable developer-extras before using " - "the webinspector!") - return + raise CommandError("Please enable developer-extras before " + "using the webinspector!") else: cur.inspector.show() @@ -660,8 +658,7 @@ class CommandDispatcher: elem = frame.findFirstElement(webelem.SELECTORS[ webelem.Group.editable_focused]) if elem.isNull(): - message.error("No editable element focused!") - return + raise CommandError("No editable element focused!") text = elem.evaluateJavaScript('this.value') self._editor = ExternalEditor() self._editor.editing_finished.connect( @@ -678,7 +675,6 @@ class CommandDispatcher: text: The new text to insert. """ if elem.isNull(): - message.error("Element vanished while editing!") - return + raise CommandError("Element vanished while editing!") text = webelem.javascript_escape(text) elem.evaluateJavaScript("this.value='{}'".format(text)) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 378ecfa0f..287376196 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -28,6 +28,7 @@ from PyQt5.QtCore import (pyqtSignal, QObject, QThread, QStandardPaths, import qutebrowser.utils.message as message from qutebrowser.utils.misc import get_standard_dir from qutebrowser.utils.log import procs as logger +from qutebrowser.commands.exceptions import CommandError class _BlockingFIFOReader(QObject): @@ -138,6 +139,8 @@ class _BaseUserscriptRunner(QObject): try: os.remove(self.filepath) except PermissionError: + # NOTE: Do not replace this with "raise CommandError" as it's + # executed async. message.error("Failed to delete tempfile...") self.filepath = None self.proc = None @@ -164,6 +167,8 @@ class _BaseUserscriptRunner(QObject): def on_proc_error(self, error): """Called when the process encountered an error.""" msg = self.PROCESS_MESSAGES[error] + # NOTE: Do not replace this with "raise CommandError" as it's + # executed async. message.error("Error while calling userscript: {}".format(msg)) @@ -284,7 +289,7 @@ class _DummyUserscriptRunner: def run(self, _cmd, *_args, _env=None): """Print an error as userscripts are not supported.""" - message.error("Userscripts are not supported on this platform!") + raise CommandError("Userscripts are not supported on this platform!") # Here we basically just assign a generic UserscriptRunner class which does the diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index b4c96e857..3d63977ed 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -303,7 +303,7 @@ class ConfigManager(QObject): self.set('conf', sectname, optname, value) except (NoOptionError, NoSectionError, ValidationError, ValueError) as e: - message.error("set: {} - {}".format(e.__class__.__name__, e)) + raise CommandError("set: {} - {}".format(e.__class__.__name__, e)) @cmdutils.register(name='set-temp', instance='config', completion=['section', 'option', 'value']) @@ -315,7 +315,7 @@ class ConfigManager(QObject): try: self.set('temp', sectname, optname, value) except (NoOptionError, NoSectionError, ValidationError) as e: - message.error("set: {} - {}".format(e.__class__.__name__, e)) + raise CommandError("set: {} - {}".format(e.__class__.__name__, e)) def set(self, layer, sectname, optname, value): """Set an option. diff --git a/qutebrowser/utils/editor.py b/qutebrowser/utils/editor.py index 9d46b1620..282d12617 100644 --- a/qutebrowser/utils/editor.py +++ b/qutebrowser/utils/editor.py @@ -46,6 +46,8 @@ class ExternalEditor(QObject): try: os.remove(self.filename) except PermissionError: + # NOTE: Do not replace this with "raise CommandError" as it's + # executed async. message.error("Failed to delete tempfile...") self.text = None self.oshandle = None @@ -67,6 +69,8 @@ class ExternalEditor(QObject): return try: if exitcode != 0: + # NOTE: Do not replace this with "raise CommandError" as it's + # executed async. message.error("Editor did quit abnormally (status {})!".format( exitcode)) return @@ -89,6 +93,8 @@ class ExternalEditor(QObject): "from the process."), QProcess.UnknownError: "An unknown error occurred.", } + # NOTE: Do not replace this with "raise CommandError" as it's + # executed async. message.error("Error while calling editor: {}".format(messages[error])) self._cleanup()