From f70ad71f9c707f6038b67075f7fee33f3611295f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 19 Feb 2014 11:10:26 +0100 Subject: [PATCH] Add error strings to exceptions --- qutebrowser/app.py | 2 +- qutebrowser/commands/template.py | 3 ++- qutebrowser/commands/utils.py | 4 ++-- qutebrowser/models/completion.py | 4 ++-- qutebrowser/utils/about.py | 2 +- qutebrowser/utils/url.py | 6 ++++-- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index e29e7f9f4..dbac5af7a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -409,7 +409,7 @@ class QuteBrowser(QApplication): Always raises Exception. """ - raise Exception + raise Exception("Forced crash") @pyqtSlot() def shutdown(self, do_quit=True): diff --git a/qutebrowser/commands/template.py b/qutebrowser/commands/template.py index 857e6ffe8..087589bb3 100644 --- a/qutebrowser/commands/template.py +++ b/qutebrowser/commands/template.py @@ -74,7 +74,8 @@ class Command(QObject): (self.nargs == '?' and len(args) > 1) or (self.nargs == '+' and len(args) < 1)): # for nargs == '*', anything is okay - raise ArgumentCountError + raise ArgumentCountError("{} args expected, but got {}".format( + self.nargs, len(args))) def run(self, args=None, count=None): """Run the command. diff --git a/qutebrowser/commands/utils.py b/qutebrowser/commands/utils.py index 89a77f9a6..5f6225847 100644 --- a/qutebrowser/commands/utils.py +++ b/qutebrowser/commands/utils.py @@ -160,12 +160,12 @@ class CommandParser(QObject): """ parts = text.strip().split(maxsplit=1) if not parts: - raise NoSuchCommandError + raise NoSuchCommandError("No command given") cmdstr = parts[0] try: cmd = cmd_dict[cmdstr] except KeyError: - raise NoSuchCommandError(cmdstr) + raise NoSuchCommandError("Command {} not found.".format(cmdstr)) if len(parts) == 1: args = [] diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index e738954e6..644a38593 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -362,7 +362,7 @@ class CompletionItem(): elif role == Qt.UserRole: return self._marks else: - raise ValueError + raise ValueError("Invalid role {}".format(role)) def setdata(self, column, value, role=Qt.DisplayRole): """Set the data for column/role to value. @@ -381,7 +381,7 @@ class CompletionItem(): elif role == Qt.UserRole: self._marks = value else: - raise ValueError + raise ValueError("Invalid role {}".format(role)) def column_count(self): """Get the column count in the item. diff --git a/qutebrowser/utils/about.py b/qutebrowser/utils/about.py index 27cbeb1c0..6e3496a94 100644 --- a/qutebrowser/utils/about.py +++ b/qutebrowser/utils/about.py @@ -52,7 +52,7 @@ def handle(url): """ if not is_about_url(url): - raise ValueError + raise ValueError("URL {} is not an about URL".format(url)) handler = getattr(AboutHandlers, _transform_url(url)) return handler() diff --git a/qutebrowser/utils/url.py b/qutebrowser/utils/url.py index 4691e66df..7e8a14bf8 100644 --- a/qutebrowser/utils/url.py +++ b/qutebrowser/utils/url.py @@ -54,8 +54,10 @@ def _get_search_url(txt): fallback=None) term = txt logging.debug('engine: default, term "{}"'.format(txt)) - if template is None or not term: - raise ValueError + if template is None: + raise ValueError("Search template is None") + if not term: + raise ValueError("No search term given") return QUrl.fromUserInput(template.format(urllib.parse.quote(term)))