Don't raise CommandError in TabbedBrowser.current_url.
TabbedBrowser.current_url used to process the qtutils.QtValueError exception and raise a cmdexc.CommandError based on it. While this was useful for some callers, it made handling it in others weird, and it doesn't really belong there - so now the caller handles this.
This commit is contained in:
parent
04c8a17b2e
commit
b8a04f5309
@ -92,7 +92,14 @@ class CommandDispatcher:
|
||||
|
||||
def _current_url(self):
|
||||
"""Convenience method to get the current url."""
|
||||
return self._tabbed_browser().current_url()
|
||||
try:
|
||||
return self._tabbed_browser().current_url()
|
||||
except qtutils.QtValueError as e:
|
||||
msg = "Current URL is invalid"
|
||||
if e.reason:
|
||||
msg += " ({})".format(e.reason)
|
||||
msg += "!"
|
||||
raise cmdexc.CommandError(msg)
|
||||
|
||||
def _current_widget(self):
|
||||
"""Get the currently active widget from a command."""
|
||||
|
@ -26,7 +26,7 @@ from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
from qutebrowser.config import config, configexc
|
||||
from qutebrowser.commands import cmdexc, cmdutils
|
||||
from qutebrowser.utils import message, log, utils, objreg
|
||||
from qutebrowser.utils import message, log, utils, objreg, qtutils
|
||||
from qutebrowser.misc import split
|
||||
|
||||
|
||||
@ -35,12 +35,18 @@ def replace_variables(win_id, arglist):
|
||||
args = []
|
||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||
window=win_id)
|
||||
for arg in arglist:
|
||||
if arg == '{url}':
|
||||
# Note we have to do this in here as the user gets an error message
|
||||
# by current_url if no URL is open yet.
|
||||
if '{url}' in arglist:
|
||||
try:
|
||||
url = tabbed_browser.current_url().toString(QUrl.FullyEncoded |
|
||||
QUrl.RemovePassword)
|
||||
except qtutils.QtValueError as e:
|
||||
msg = "Current URL is invalid"
|
||||
if e.reason:
|
||||
msg += " ({})".format(e.reason)
|
||||
msg += "!"
|
||||
raise cmdexc.CommandError(msg)
|
||||
for arg in arglist:
|
||||
if arg == '{url}':
|
||||
args.append(url)
|
||||
else:
|
||||
args.append(arg)
|
||||
|
@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers
|
||||
from qutebrowser.commands import cmdexc, cmdutils
|
||||
from qutebrowser.misc import cmdhistory
|
||||
from qutebrowser.misc import miscwidgets as misc
|
||||
from qutebrowser.utils import usertypes, log, objreg
|
||||
from qutebrowser.utils import usertypes, log, objreg, qtutils
|
||||
|
||||
|
||||
class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
@ -110,8 +110,15 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||
window=self._win_id)
|
||||
if '{url}' in text:
|
||||
url = tabbed_browser.current_url().toString(
|
||||
QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||
try:
|
||||
url = tabbed_browser.current_url().toString(
|
||||
QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||
except qtutils.QtValueError as e:
|
||||
msg = "Current URL is invalid"
|
||||
if e.reason:
|
||||
msg += " ({})".format(e.reason)
|
||||
msg += "!"
|
||||
raise cmdexc.CommandError(msg)
|
||||
# FIXME we currently replace the URL in any place in the arguments,
|
||||
# rather than just replacing it if it is a dedicated argument. We
|
||||
# could split the args, but then trailing spaces would be lost, so
|
||||
|
@ -28,7 +28,6 @@ from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.commands import cmdexc
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.mainwindow import tabwidget
|
||||
from qutebrowser.browser import signalfilter, commands, webview
|
||||
@ -187,14 +186,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
url = QUrl()
|
||||
else:
|
||||
url = widget.cur_url
|
||||
try:
|
||||
qtutils.ensure_valid(url)
|
||||
except qtutils.QtValueError as e:
|
||||
msg = "Current URL is invalid"
|
||||
if e.reason:
|
||||
msg += " ({})".format(e.reason)
|
||||
msg += "!"
|
||||
raise cmdexc.CommandError(msg)
|
||||
# It's possible for url to be invalid, but the caller will handle that.
|
||||
qtutils.ensure_valid(url)
|
||||
return url
|
||||
|
||||
def shutdown(self):
|
||||
|
Loading…
Reference in New Issue
Block a user