Raise CommandError instead of message.error where possible

This commit is contained in:
Florian Bruhin 2014-06-06 11:55:55 +02:00
parent 118dace031
commit fd220b1b36
4 changed files with 20 additions and 13 deletions

View File

@ -631,9 +631,8 @@ class CommandDispatcher:
cur = self._tabs.currentWidget() cur = self._tabs.currentWidget()
if cur.inspector is None: if cur.inspector is None:
if not config.get('general', 'developer-extras'): if not config.get('general', 'developer-extras'):
message.error("Please enable developer-extras before using " raise CommandError("Please enable developer-extras before "
"the webinspector!") "using the webinspector!")
return
cur.inspector = QWebInspector() cur.inspector = QWebInspector()
cur.inspector.setPage(cur.page()) cur.inspector.setPage(cur.page())
cur.inspector.show() cur.inspector.show()
@ -641,9 +640,8 @@ class CommandDispatcher:
cur.inspector.hide() cur.inspector.hide()
else: else:
if not config.get('general', 'developer-extras'): if not config.get('general', 'developer-extras'):
message.error("Please enable developer-extras before using " raise CommandError("Please enable developer-extras before "
"the webinspector!") "using the webinspector!")
return
else: else:
cur.inspector.show() cur.inspector.show()
@ -660,8 +658,7 @@ class CommandDispatcher:
elem = frame.findFirstElement(webelem.SELECTORS[ elem = frame.findFirstElement(webelem.SELECTORS[
webelem.Group.editable_focused]) webelem.Group.editable_focused])
if elem.isNull(): if elem.isNull():
message.error("No editable element focused!") raise CommandError("No editable element focused!")
return
text = elem.evaluateJavaScript('this.value') text = elem.evaluateJavaScript('this.value')
self._editor = ExternalEditor() self._editor = ExternalEditor()
self._editor.editing_finished.connect( self._editor.editing_finished.connect(
@ -678,7 +675,6 @@ class CommandDispatcher:
text: The new text to insert. text: The new text to insert.
""" """
if elem.isNull(): if elem.isNull():
message.error("Element vanished while editing!") raise CommandError("Element vanished while editing!")
return
text = webelem.javascript_escape(text) text = webelem.javascript_escape(text)
elem.evaluateJavaScript("this.value='{}'".format(text)) elem.evaluateJavaScript("this.value='{}'".format(text))

View File

@ -28,6 +28,7 @@ from PyQt5.QtCore import (pyqtSignal, QObject, QThread, QStandardPaths,
import qutebrowser.utils.message as message import qutebrowser.utils.message as message
from qutebrowser.utils.misc import get_standard_dir from qutebrowser.utils.misc import get_standard_dir
from qutebrowser.utils.log import procs as logger from qutebrowser.utils.log import procs as logger
from qutebrowser.commands.exceptions import CommandError
class _BlockingFIFOReader(QObject): class _BlockingFIFOReader(QObject):
@ -138,6 +139,8 @@ class _BaseUserscriptRunner(QObject):
try: try:
os.remove(self.filepath) os.remove(self.filepath)
except PermissionError: except PermissionError:
# NOTE: Do not replace this with "raise CommandError" as it's
# executed async.
message.error("Failed to delete tempfile...") message.error("Failed to delete tempfile...")
self.filepath = None self.filepath = None
self.proc = None self.proc = None
@ -164,6 +167,8 @@ class _BaseUserscriptRunner(QObject):
def on_proc_error(self, error): def on_proc_error(self, error):
"""Called when the process encountered an error.""" """Called when the process encountered an error."""
msg = self.PROCESS_MESSAGES[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)) message.error("Error while calling userscript: {}".format(msg))
@ -284,7 +289,7 @@ class _DummyUserscriptRunner:
def run(self, _cmd, *_args, _env=None): def run(self, _cmd, *_args, _env=None):
"""Print an error as userscripts are not supported.""" """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 # Here we basically just assign a generic UserscriptRunner class which does the

View File

@ -303,7 +303,7 @@ class ConfigManager(QObject):
self.set('conf', sectname, optname, value) self.set('conf', sectname, optname, value)
except (NoOptionError, NoSectionError, ValidationError, except (NoOptionError, NoSectionError, ValidationError,
ValueError) as e: 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', @cmdutils.register(name='set-temp', instance='config',
completion=['section', 'option', 'value']) completion=['section', 'option', 'value'])
@ -315,7 +315,7 @@ class ConfigManager(QObject):
try: try:
self.set('temp', sectname, optname, value) self.set('temp', sectname, optname, value)
except (NoOptionError, NoSectionError, ValidationError) as e: 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): def set(self, layer, sectname, optname, value):
"""Set an option. """Set an option.

View File

@ -46,6 +46,8 @@ class ExternalEditor(QObject):
try: try:
os.remove(self.filename) os.remove(self.filename)
except PermissionError: except PermissionError:
# NOTE: Do not replace this with "raise CommandError" as it's
# executed async.
message.error("Failed to delete tempfile...") message.error("Failed to delete tempfile...")
self.text = None self.text = None
self.oshandle = None self.oshandle = None
@ -67,6 +69,8 @@ class ExternalEditor(QObject):
return return
try: try:
if exitcode != 0: if exitcode != 0:
# NOTE: Do not replace this with "raise CommandError" as it's
# executed async.
message.error("Editor did quit abnormally (status {})!".format( message.error("Editor did quit abnormally (status {})!".format(
exitcode)) exitcode))
return return
@ -89,6 +93,8 @@ class ExternalEditor(QObject):
"from the process."), "from the process."),
QProcess.UnknownError: "An unknown error occurred.", 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])) message.error("Error while calling editor: {}".format(messages[error]))
self._cleanup() self._cleanup()