Add a raise_cmdexc_if_invalid to urlutils.
This commit is contained in:
parent
41c3a59e81
commit
75d1f072c2
@ -109,11 +109,7 @@ class CommandDispatcher:
|
||||
background: Whether to open in the background.
|
||||
window: Whether to open in a new window
|
||||
"""
|
||||
if not url.isValid():
|
||||
errstr = "Invalid URL {}"
|
||||
if url.errorString():
|
||||
errstr += " - {}".format(url.errorString())
|
||||
raise cmdexc.CommandError(errstr)
|
||||
urlutils.raise_cmdexc_if_invalid(url)
|
||||
tabbed_browser = self._tabbed_browser()
|
||||
cmdutils.check_exclusive((tab, background, window), 'tbw')
|
||||
if window:
|
||||
|
@ -29,6 +29,7 @@ from PyQt5.QtNetwork import QHostInfo
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import log, qtutils, message
|
||||
from qutebrowser.commands import cmdexc
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
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):
|
||||
|
||||
"""Exception raised by fuzzy_url on problems."""
|
||||
|
Loading…
Reference in New Issue
Block a user