diff --git a/qutebrowser/browser/quickmarks.py b/qutebrowser/browser/quickmarks.py index 62c2037db..b41c9888f 100644 --- a/qutebrowser/browser/quickmarks.py +++ b/qutebrowser/browser/quickmarks.py @@ -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 diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 649044fa1..3efc91ad7 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -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())