Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / 9e / 7cece21551de20a5ba570c42ee515952cafee2
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \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
22  (PDT)\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
36         [80.192.18.48])\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
47 MIME-Version: 1.0\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
56 Precedence: list\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
67 \r
68 \r
69 --fdj2RfSjLxBAspz7\r
70 Content-Type: text/plain; charset=us-ascii\r
71 Content-Disposition: inline\r
72 Content-Transfer-Encoding: quoted-printable\r
73 \r
74 Hi all,\r
75 \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
79  any\r
80 way by calling these prints garbage! It's just that it's highly unusual and=\r
81  very\r
82 'non-pythonic' that a module directly prints to stderr instead of raising e=\r
83 xceptions\r
84 and if you work directly with a curseslike interface on a terminal these\r
85 errormessages litter my screen.\r
86 \r
87 The patch I send is a suggestion how to fix the behaviour described in my l=\r
88 ast post.\r
89 It introduces a ContextManager class that can be used to raise messages fro=\r
90 m stderr\r
91 as Xapian exceptions like this:\r
92 \r
93 > from notmuch.globals import RaiseStderrErrors\r
94 > with RaiseStderrErrors():\r
95 >  do_stuff()\r
96 \r
97 Now, if one executes:=20\r
98 ------------\r
99 > from notmuch import Database\r
100 > bad_querystring =3D "test AND"\r
101 > query =3D Database().create_query(bad_querystring\r
102 ---------------\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
111 14, in __init__\r
112     self.create(db, querystr)\r
113   File "/usr/local/lib/python2.7/dist-packages/notmuch/database.py", line 5=\r
114 47, in create\r
115     Query._count_messages(self._query)\r
116   File "/usr/local/lib/python2.7/dist-packages/notmuch/globals.py", line 12=\r
117 3, in __exit__\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
123 \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
126 ork since\r
127 just replacing sys.stderr with something else is not "low level" enough, th=\r
128 e messages will\r
129 still get printed. An alternative is using os.dup2, which replaces the file=\r
130  descriptor\r
131 of stderr directly, but cStringIO objects dont have .fileno()..\r
132 see [0,1].\r
133 The second problem is, that creating a query object with a malformed querys=\r
134 tring doesn't\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
141 \r
142 best,\r
143 /p\r
144 \r
145 \r
146 \r
147 ----\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
152 \r
153 \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
156 ail.com> wrote:\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
160 >=20\r
161 > I wouldn't call that "xapian-garbage" since it is output from\r
162 > libnotmuch.\r
163 >=20\r
164 > d\r
165 \r
166 --fdj2RfSjLxBAspz7\r
167 Content-Type: application/pgp-signature; name="signature.asc"\r
168 Content-Description: Digital signature\r
169 \r
170 -----BEGIN PGP SIGNATURE-----\r
171 Version: GnuPG v1.4.11 (GNU/Linux)\r
172 \r
173 iEYEARECAAYFAk4qzkIACgkQlDQDZ9fWxar8EACgrSVyAbS67aXjWLzeBpoJuzBb\r
174 rwYAn0EJ3Sfqsw6zTlew+oGuubWgRuXz\r
175 =tQEF\r
176 -----END PGP SIGNATURE-----\r
177 \r
178 --fdj2RfSjLxBAspz7--\r