1 Return-Path: <patricktotzke@googlemail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 24044431FD0
\r
6 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:12:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
10 X-Spam-Score: -0.799
\r
12 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
13 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
14 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id Vzw8zLDDSchG for <notmuch@notmuchmail.org>;
\r
18 Sat, 23 Jul 2011 06:12:57 -0700 (PDT)
\r
19 Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com
\r
20 [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id 9A710431FB6
\r
23 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:12:56 -0700 (PDT)
\r
24 Received: by wyh22 with SMTP id 22so2327529wyh.26
\r
25 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:12:55 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
27 d=googlemail.com; s=gamma;
\r
28 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references
\r
29 :in-reply-to:references;
\r
30 bh=CjckEnceHtxo/0XwRNhzNET2z4Lhakgf+cqrhkCOV70=;
\r
31 b=TQmTPYpn8qGK6NIl3Go2htxPv0KvYp9e8rkaR+B7fwk82RjKW2PTEemnJxqsDIwltM
\r
32 odP2Rkx5jNA546ozIKn+xIGWGiE3B5nGFQCNjPisu8d9i8LDEwYrJEPQmqBzLug6WNuF
\r
33 dmdDWObBKp4mTLycAisIPMW2LFZIymIAZnUyo=
\r
34 Received: by 10.227.6.18 with SMTP id 18mr2307644wbx.66.1311426775086;
\r
35 Sat, 23 Jul 2011 06:12:55 -0700 (PDT)
\r
36 Received: from localhost (cpc1-sgyl2-0-0-cust47.sgyl.cable.virginmedia.com
\r
38 by mx.google.com with ESMTPS id gb1sm2710367wbb.37.2011.07.23.06.12.53
\r
39 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Sat, 23 Jul 2011 06:12:54 -0700 (PDT)
\r
41 From: pazz <patricktotzke@googlemail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH] interpret Xapian errors from sdterr as exceptions
\r
44 Date: Sat, 23 Jul 2011 14:12:39 +0100
\r
45 Message-Id: <1311426759-32441-1-git-send-email-patricktotzke@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.4.1
\r
47 In-Reply-To: <87r55o65yq.fsf@zancas.localnet>
\r
48 References: <87r55o65yq.fsf@zancas.localnet>
\r
49 In-Reply-To: <87r55o65yq.fsf@zancas.localnet>
\r
50 References: <87r55o65yq.fsf@zancas.localnet>
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Sat, 23 Jul 2011 13:12:59 -0000
\r
65 This introduces globals.RaiseStderrErrors, a ContextManager
\r
66 that raises error messages printed by libnotmuch to stderr
\r
67 as NotmuchError(STATUS.XAPIAN_EXCEPTION, message=err).
\r
69 bindings/python/notmuch/database.py | 5 +++++
\r
70 bindings/python/notmuch/globals.py | 24 ++++++++++++++++++++++++
\r
71 2 files changed, 29 insertions(+), 0 deletions(-)
\r
73 diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
\r
74 index 874087e..443980b 100644
\r
75 --- a/bindings/python/notmuch/database.py
\r
76 +++ b/bindings/python/notmuch/database.py
\r
77 @@ -18,8 +18,10 @@ Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
82 from ctypes import c_int, c_char_p, c_void_p, c_uint, c_long, byref
\r
83 from notmuch.globals import nmlib, STATUS, NotmuchError, Enum
\r
84 +from notmuch.globals import RaiseStderrErrors
\r
85 from notmuch.thread import Threads
\r
86 from notmuch.message import Messages, Message
\r
87 from notmuch.tag import Tags
\r
88 @@ -540,6 +542,9 @@ class Query(object):
\r
90 NotmuchError(STATUS.NULL_POINTER)
\r
91 self._query = query_p
\r
92 + # ensure Xapian errors from stderr get raised if query syntax is bad
\r
93 + with RaiseStderrErrors():
\r
94 + Query._count_messages(self._query)
\r
96 def set_sort(self, sort):
\r
97 """Set the sort order future results will be delivered in
\r
98 diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
\r
99 index 77f2905..5e527ca 100644
\r
100 --- a/bindings/python/notmuch/globals.py
\r
101 +++ b/bindings/python/notmuch/globals.py
\r
102 @@ -17,6 +17,10 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
103 Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
\r
110 from ctypes import CDLL, c_char_p, c_int
\r
111 from ctypes.util import find_library
\r
113 @@ -98,3 +102,23 @@ class NotmuchError(Exception):
\r
114 return self.args[0]
\r
116 return STATUS.status2str(self.args[1])
\r
119 +class RaiseStderrErrors:
\r
120 + def __enter__(self):
\r
121 + sys.stderr.flush()
\r
122 + (self.errfd, fn) = tempfile.mkstemp()
\r
123 + self.ferr = os.fdopen(self.errfd, 'r')
\r
125 + self.oldstderr = os.dup(sys.stderr.fileno())
\r
126 + os.dup2(self.errfd, sys.stderr.fileno())
\r
128 + def __exit__(self, *args):
\r
129 + sys.stderr.flush()
\r
130 + os.dup2(self.oldstderr, sys.stderr.fileno())
\r
131 + os.close(self.oldstderr)
\r
132 + os.lseek(self.errfd, 0, 0)
\r
133 + err = self.ferr.read()
\r
135 + raise NotmuchError(STATUS.XAPIAN_EXCEPTION, message=err)
\r
136 + self.ferr.close()
\r