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 5D192431FD0
\r
6 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:36:10 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id GLzLMHh5wRPN for <notmuch@notmuchmail.org>;
\r
17 Sat, 23 Jul 2011 06:36:09 -0700 (PDT)
\r
18 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com
\r
19 [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
20 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
21 695C4431FB6 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:36:09 -0700
\r
23 Received: by wwj40 with SMTP id 40so2969398wwj.2
\r
24 for <notmuch@notmuchmail.org>; Sat, 23 Jul 2011 06:36:08 -0700 (PDT)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=googlemail.com; s=gamma;
\r
27 h=date:from:to:cc:subject:message-id:references:mime-version
\r
28 :content-type:content-disposition:in-reply-to:user-agent;
\r
29 bh=B39JvdJ0sZ3A/s+2N6/Lv4ks2V5ZMMpUY0hXQOVkrnc=;
\r
30 b=pJEs4Abucr9mqhHLDbvQp81H53LWBHlXixvFKhII+dVyAHQwGVgISHNUPMGxgSxYWc
\r
31 +08cmtQkkh0rDaS8dvVtCQkk4NYlZt6AzRIVHpCW2Pqcw+GoUF/AMczUkq5/Bh0H6xld
\r
32 +c4v+tQIYZstrohFQyQjowAjJwJu2ACCtUC4c=
\r
33 Received: by 10.216.173.81 with SMTP id u59mr2304759wel.4.1311428168011;
\r
34 Sat, 23 Jul 2011 06:36:08 -0700 (PDT)
\r
35 Received: from brick.lan (cpc1-sgyl2-0-0-cust47.sgyl.cable.virginmedia.com
\r
37 by mx.google.com with ESMTPS id l61sm1118717wed.28.2011.07.23.06.36.04
\r
38 (version=TLSv1/SSLv3 cipher=OTHER);
\r
39 Sat, 23 Jul 2011 06:36:05 -0700 (PDT)
\r
40 Date: Sat, 23 Jul 2011 14:36:02 +0100
\r
41 From: Patrick Totzke <patricktotzke@googlemail.com>
\r
42 To: David Bremner <david@tethera.net>
\r
43 Subject: Re: xapian exceptions not caught in python bindings?
\r
44 Message-ID: <20110723133602.GA30241@brick.lan>
\r
45 References: <20110626202733.GA26837@brick> <20110717193538.GA16615@brick.lan>
\r
46 <87r55o65yq.fsf@zancas.localnet>
\r
48 Content-Type: multipart/signed; micalg=pgp-sha1;
\r
49 protocol="application/pgp-signature"; boundary="fdj2RfSjLxBAspz7"
\r
50 Content-Disposition: inline
\r
51 In-Reply-To: <87r55o65yq.fsf@zancas.localnet>
\r
52 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
53 Cc: Patrick Totzke <patricktotzke@googlemail.com>, notmuch@notmuchmail.org
\r
54 X-BeenThere: notmuch@notmuchmail.org
\r
55 X-Mailman-Version: 2.1.13
\r
57 List-Id: "Use and development of the notmuch mail system."
\r
58 <notmuch.notmuchmail.org>
\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
62 List-Post: <mailto:notmuch@notmuchmail.org>
\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
66 X-List-Received-Date: Sat, 23 Jul 2011 13:36:10 -0000
\r
70 Content-Type: text/plain; charset=us-ascii
\r
71 Content-Disposition: inline
\r
72 Content-Transfer-Encoding: quoted-printable
\r
76 I hope the patch I send is correctly formated, I'm still fumbling with
\r
77 git send-email and the --in-reply-to option.
\r
78 Anyhow, forgive my language, of course I didn't mean to be condescending in=
\r
80 way by calling these prints garbage! It's just that it's highly unusual and=
\r
82 'non-pythonic' that a module directly prints to stderr instead of raising e=
\r
84 and if you work directly with a curseslike interface on a terminal these
\r
85 errormessages litter my screen.
\r
87 The patch I send is a suggestion how to fix the behaviour described in my l=
\r
89 It introduces a ContextManager class that can be used to raise messages fro=
\r
91 as Xapian exceptions like this:
\r
93 > from notmuch.globals import RaiseStderrErrors
\r
94 > with RaiseStderrErrors():
\r
97 Now, if one executes:=20
\r
99 > from notmuch import Database
\r
100 > bad_querystring =3D "test AND"
\r
101 > query =3D Database().create_query(bad_querystring
\r
103 one gets a nice Xapian exception
\r
104 -----------------------
\r
105 File "syntax.py", line 4, in <module>
\r
106 query =3D Database().create_query(bad_querystring)
\r
107 File "/usr/local/lib/python2.7/dist-packages/notmuch/database.py", line 4=
\r
108 32, in create_query
\r
109 return Query(self, querystring)
\r
110 File "/usr/local/lib/python2.7/dist-packages/notmuch/database.py", line 5=
\r
112 self.create(db, querystr)
\r
113 File "/usr/local/lib/python2.7/dist-packages/notmuch/database.py", line 5=
\r
115 Query._count_messages(self._query)
\r
116 File "/usr/local/lib/python2.7/dist-packages/notmuch/globals.py", line 12=
\r
118 raise NotmuchError(STATUS.XAPIAN_EXCEPTION, message=3Derr)
\r
119 notmuch.globals.NotmuchError: A Xapian exception occurred: Syntax: <express=
\r
120 ion> AND <expression>
\r
121 Query string was: test AND
\r
122 ----------------------------
\r
124 There are two problems with this suggestion however.
\r
125 First, one needs to redirect sdterr to a tempfile: Using StringIO doesn't w=
\r
127 just replacing sys.stderr with something else is not "low level" enough, th=
\r
129 still get printed. An alternative is using os.dup2, which replaces the file=
\r
131 of stderr directly, but cStringIO objects dont have .fileno()..
\r
133 The second problem is, that creating a query object with a malformed querys=
\r
135 print anything to stderr, only if you use that object errors get printed (n=
\r
136 otmuch/lib/query.cc).
\r
137 Thus, I call count_messages() once after initialising a new notmuch.databas=
\r
138 =2EQuery object (at the end of Query.create). This ensures that Query.__in=
\r
139 it__() raises an exception when given bad=20
\r
140 querystrings, but at the cost of triggering an unnecessary count_messages().
\r
148 [0]: http://stackoverflow.com/questions/5903501/attributeerror-stringio-ins=
\r
149 tance-has-no-attribute-fileno
\r
150 [1]: http://code.activestate.com/recipes/577564-context-manager-for-low-lev=
\r
151 el-redirection-of-stdou/
\r
154 On Sun, Jul 17, 2011 at 04:51:41PM -0300, David Bremner wrote:
\r
155 > On Sun, 17 Jul 2011 20:35:38 +0100, Patrick Totzke <patricktotzke@googlem=
\r
157 > > If you run the following snippet, you notice that not only do we get
\r
158 > > xapian-garbage on stderr but we don't really get any exceptions at the
\r
159 > > position where it would make sense:
\r
161 > I wouldn't call that "xapian-garbage" since it is output from
\r
167 Content-Type: application/pgp-signature; name="signature.asc"
\r
168 Content-Description: Digital signature
\r
170 -----BEGIN PGP SIGNATURE-----
\r
171 Version: GnuPG v1.4.11 (GNU/Linux)
\r
173 iEYEARECAAYFAk4qzkIACgkQlDQDZ9fWxar8EACgrSVyAbS67aXjWLzeBpoJuzBb
\r
174 rwYAn0EJ3Sfqsw6zTlew+oGuubWgRuXz
\r
176 -----END PGP SIGNATURE-----
\r
178 --fdj2RfSjLxBAspz7--
\r