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):
|
def _current_url(self):
|
||||||
"""Convenience method to get the current url."""
|
"""Convenience method to get the current url."""
|
||||||
|
try:
|
||||||
return self._tabbed_browser().current_url()
|
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):
|
def _current_widget(self):
|
||||||
"""Get the currently active widget from a command."""
|
"""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.config import config, configexc
|
||||||
from qutebrowser.commands import cmdexc, cmdutils
|
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
|
from qutebrowser.misc import split
|
||||||
|
|
||||||
|
|
||||||
@ -35,12 +35,18 @@ def replace_variables(win_id, arglist):
|
|||||||
args = []
|
args = []
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
for arg in arglist:
|
if '{url}' in arglist:
|
||||||
if arg == '{url}':
|
try:
|
||||||
# Note we have to do this in here as the user gets an error message
|
|
||||||
# by current_url if no URL is open yet.
|
|
||||||
url = tabbed_browser.current_url().toString(QUrl.FullyEncoded |
|
url = tabbed_browser.current_url().toString(QUrl.FullyEncoded |
|
||||||
QUrl.RemovePassword)
|
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)
|
args.append(url)
|
||||||
else:
|
else:
|
||||||
args.append(arg)
|
args.append(arg)
|
||||||
|
@ -26,7 +26,7 @@ from qutebrowser.keyinput import modeman, modeparsers
|
|||||||
from qutebrowser.commands import cmdexc, cmdutils
|
from qutebrowser.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.misc import cmdhistory
|
from qutebrowser.misc import cmdhistory
|
||||||
from qutebrowser.misc import miscwidgets as misc
|
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):
|
class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||||
@ -110,8 +110,15 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
|||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
if '{url}' in text:
|
if '{url}' in text:
|
||||||
|
try:
|
||||||
url = tabbed_browser.current_url().toString(
|
url = tabbed_browser.current_url().toString(
|
||||||
QUrl.FullyEncoded | QUrl.RemovePassword)
|
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,
|
# FIXME we currently replace the URL in any place in the arguments,
|
||||||
# rather than just replacing it if it is a dedicated argument. We
|
# rather than just replacing it if it is a dedicated argument. We
|
||||||
# could split the args, but then trailing spaces would be lost, so
|
# 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 PyQt5.QtWebKitWidgets import QWebPage
|
||||||
|
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.commands import cmdexc
|
|
||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman
|
||||||
from qutebrowser.mainwindow import tabwidget
|
from qutebrowser.mainwindow import tabwidget
|
||||||
from qutebrowser.browser import signalfilter, commands, webview
|
from qutebrowser.browser import signalfilter, commands, webview
|
||||||
@ -187,14 +186,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
url = QUrl()
|
url = QUrl()
|
||||||
else:
|
else:
|
||||||
url = widget.cur_url
|
url = widget.cur_url
|
||||||
try:
|
# It's possible for url to be invalid, but the caller will handle that.
|
||||||
qtutils.ensure_valid(url)
|
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)
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user