Add a raise_cmdexc_if_invalid to urlutils.

This commit is contained in:
Florian Bruhin 2014-11-18 19:49:31 +01:00
parent 41c3a59e81
commit 75d1f072c2
2 changed files with 12 additions and 5 deletions

View File

@ -109,11 +109,7 @@ class CommandDispatcher:
background: Whether to open in the background. background: Whether to open in the background.
window: Whether to open in a new window window: Whether to open in a new window
""" """
if not url.isValid(): urlutils.raise_cmdexc_if_invalid(url)
errstr = "Invalid URL {}"
if url.errorString():
errstr += " - {}".format(url.errorString())
raise cmdexc.CommandError(errstr)
tabbed_browser = self._tabbed_browser() tabbed_browser = self._tabbed_browser()
cmdutils.check_exclusive((tab, background, window), 'tbw') cmdutils.check_exclusive((tab, background, window), 'tbw')
if window: if window:

View File

@ -29,6 +29,7 @@ from PyQt5.QtNetwork import QHostInfo
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.utils import log, qtutils, message from qutebrowser.utils import log, qtutils, message
from qutebrowser.commands import cmdexc
# FIXME: we probably could raise some exceptions on invalid URLs # FIXME: we probably could raise some exceptions on invalid URLs
@ -272,6 +273,16 @@ def invalid_url_error(win_id, url, action):
message.error(win_id, errstring) message.error(win_id, errstring)
def raise_cmdexc_if_invalid(url):
"""Check if the given QUrl is invalid, and if so, raise a CommandError."""
if not url.isValid():
errstr = "Invalid URL {}".format(url.toDisplayString())
url_error = url.errorString()
if url_error:
errstr += " - {}".format(url_error)
raise cmdexc.CommandError(errstr)
class FuzzyUrlError(Exception): class FuzzyUrlError(Exception):
"""Exception raised by fuzzy_url on problems.""" """Exception raised by fuzzy_url on problems."""