unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Justus Winter <4winter@informatik.uni-hamburg.de>
To: notmuch@notmuchmail.org
Cc: Justus Winter <4winter@informatik.uni-hamburg.de>
Subject: [PATCH 9/9] python: raise a more specific error in Messages.print_messages
Date: Mon, 26 Sep 2011 03:05:37 +0200	[thread overview]
Message-ID: <1316999137-28257-9-git-send-email-4winter@informatik.uni-hamburg.de> (raw)
In-Reply-To: <1316999137-28257-1-git-send-email-4winter@informatik.uni-hamburg.de>

Raising Exception is considered bad since the only way to catch
it is to do 'except Exception'. Raising a TypeError is more
appropriate.

Since the format parameter has already been validated, checking
it again is not necessary. Simplify this conditional.

Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
---
 bindings/python/notmuch/message.py |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index ac708ec..a40932a 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -188,7 +188,7 @@ class Messages(object):
             set_end = "]"
             set_sep = ", "
         else:
-            raise Exception
+            raise TypeError("format must be either 'text' or 'json'")
 
         first_set = True
 
@@ -209,10 +209,8 @@ class Messages(object):
             if (match or entire_thread):
                 if format.lower() == "text":
                     sys.stdout.write(msg.format_message_as_text(indent))
-                elif format.lower() == "json":
-                    sys.stdout.write(msg.format_message_as_json(indent))
                 else:
-                    raise NotmuchError
+                    sys.stdout.write(msg.format_message_as_json(indent))
                 next_indent = indent + 1
 
             # get replies and print them also out (if there are any)
-- 
1.7.6.3

  parent reply	other threads:[~2011-09-26  1:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-26  1:05 [PATCH 1/9] python: add a .gitignore file and refine the toplevel one Justus Winter
2011-09-26  1:05 ` [PATCH 2/9] python: add status and message attributes to NotmuchError Justus Winter
2011-09-26  1:05 ` [PATCH 3/9] python: reorder the arguments of NotmuchError.__init__() Justus Winter
2011-09-26  1:05 ` [PATCH 4/9] python: fix NotmuchError.__str__ if status == None Justus Winter
2011-09-26  1:05 ` [PATCH 5/9] python: rename _verify_initialized_db to _assert_db_is_initialized Justus Winter
2011-09-26  1:05 ` [PATCH 6/9] python: rename _verify_dir_initialized to _assert_dir_is_initialized Justus Winter
2011-09-26  1:05 ` [PATCH 7/9] python: provide more exception classes Justus Winter
2011-09-30 12:00   ` Sebastian Spaeth
2011-09-30 12:23     ` Justus Winter
2011-09-26  1:05 ` [PATCH 8/9] python: use the new exception classes and update the documentation Justus Winter
2011-09-26  1:05 ` Justus Winter [this message]
2011-09-29  7:45 ` [PATCH 1/9] python: add a .gitignore file and refine the toplevel one Sebastian Spaeth
2011-09-30  0:41   ` Justus Winter
2011-09-30  9:14     ` Sebastian Spaeth
2011-09-29  7:47 ` Sebastian Spaeth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316999137-28257-9-git-send-email-4winter@informatik.uni-hamburg.de \
    --to=4winter@informatik.uni-hamburg.de \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).