Fix UnboundLocalError on invalid quickmarks.
This also improves FuzzyUrlError messages.
This commit is contained in:
parent
b2427701fa
commit
5233e7fac8
@ -147,8 +147,11 @@ class QuickmarkManager(QObject):
|
||||
urlstr = self.marks[name]
|
||||
try:
|
||||
url = urlutils.fuzzy_url(urlstr, do_search=False)
|
||||
except urlutils.FuzzyUrlError:
|
||||
raise cmdexc.CommandError(
|
||||
"Invalid URL for quickmark {}: {} ({})".format(
|
||||
name, urlstr, url.errorString()))
|
||||
except urlutils.FuzzyUrlError as e:
|
||||
if e.url is None or not e.url.errorString():
|
||||
errstr = ''
|
||||
else:
|
||||
errstr = ' ({})'.format(e.url.errorString())
|
||||
raise cmdexc.CommandError("Invalid URL for quickmark {}: "
|
||||
"{}{}".format(name, urlstr, errstr))
|
||||
return url
|
||||
|
@ -183,7 +183,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True):
|
||||
qtutils.ensure_valid(url)
|
||||
else:
|
||||
if not url.isValid():
|
||||
raise FuzzyUrlError("Invalid URL '{}'!".format(urlstr))
|
||||
raise FuzzyUrlError("Invalid URL '{}'!".format(urlstr), url)
|
||||
return url
|
||||
|
||||
|
||||
@ -357,6 +357,20 @@ def host_tuple(url):
|
||||
|
||||
class FuzzyUrlError(Exception):
|
||||
|
||||
"""Exception raised by fuzzy_url on problems."""
|
||||
"""Exception raised by fuzzy_url on problems.
|
||||
|
||||
pass
|
||||
Attributes:
|
||||
url: The QUrl which caused the error.
|
||||
"""
|
||||
|
||||
def __init__(self, msg, url=None):
|
||||
super().__init__(msg)
|
||||
if url is not None:
|
||||
assert not url.isValid()
|
||||
self.url = url
|
||||
|
||||
def __str__(self):
|
||||
if self.url is None or not self.url.errorString():
|
||||
return str(super())
|
||||
else:
|
||||
return '{}: {}'.format(str(super()), self.url.errorString())
|
||||
|
Loading…
Reference in New Issue
Block a user