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()
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))

View File

@ -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

View File

@ -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.

View File

@ -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()