1 Return-Path: <david@tethera.net>
\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 8134A431FC7
\r
6 for <notmuch@notmuchmail.org>; Tue, 16 Dec 2014 00:02:27 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id eqqo3aD5Nyv5 for <notmuch@notmuchmail.org>;
\r
16 Tue, 16 Dec 2014 00:02:24 -0800 (PST)
\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
18 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id CCC5B431FC4
\r
21 for <notmuch@notmuchmail.org>; Tue, 16 Dec 2014 00:02:24 -0800 (PST)
\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
23 (envelope-from <david@tethera.net>)
\r
24 id 1Y0n5L-00061g-F4; Tue, 16 Dec 2014 04:02:23 -0400
\r
25 Received: (nullmailer pid 4251 invoked by uid 1000); Tue, 16 Dec 2014
\r
27 From: David Bremner <david@tethera.net>
\r
28 To: Matt <mattator@gmail.com>
\r
29 Subject: Re: Python bindings and Xapian exceptions
\r
31 <CADHp1NyiuG-V2b68fsie_Fhn0kigUM88bPinhE9yZPCsWNW6QA@mail.gmail.com>
\r
32 References: <87k4q7s43v.fsf@ut.hh.sledj.net> <878w6gis5g.fsf@SSpaeth.de>
\r
33 <871v70ril7.fsf@yoom.home.cworth.org> <871v70z0y5.fsf@SSpaeth.de>
\r
34 <loom.20141215T121709-488@post.gmane.org>
\r
35 <87iohc7iiz.fsf@maritornes.cs.unb.ca>
\r
36 <CADHp1NyiuG-V2b68fsie_Fhn0kigUM88bPinhE9yZPCsWNW6QA@mail.gmail.com>
\r
37 User-Agent: Notmuch/0.19+7~g5d7f7a6 (http://notmuchmail.org) Emacs/24.4.1
\r
38 (x86_64-pc-linux-gnu)
\r
39 Date: Tue, 16 Dec 2014 09:02:17 +0100
\r
40 Message-ID: <87fvcg6n06.fsf@maritornes.cs.unb.ca>
\r
42 Content-Type: text/plain
\r
43 Cc: notmuch@notmuchmail.org
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Tue, 16 Dec 2014 08:02:27 -0000
\r
58 Matt <mattator@gmail.com> writes:
\r
60 > 2014-12-15 21:41 GMT+01:00 David Bremner <david@tethera.net>:
\r
61 >> Matt <mattator@gmail.com> writes:
\r
63 >>>> > But for exceptions in general, yes the notmuch library does need to be
\r
64 >>>> > fixed to allow the caller of functions to distinguish between things
\r
65 >>>> > like "no matches found" and "an exception occurred, so it's unknown if
\r
66 >>>> > any messages match the search". That's a general class of library
\r
67 >>>> > interface bugs that all need to be fixed.
\r
69 >>> I 've also hit this *API bug* and was wondering if a fix had been done since
\r
70 >>> then (I use notmuch 0.17) ? I found nothing on http://notmuchmail.org/news/
\r
72 >> Can you be more specific? I'd say in general no thorough overhaul of
\r
73 >> error handling has happened, but if you can tell us what particular
\r
74 >> libnotmuch function (or the equivalient python binding) you are having
\r
75 >> trouble with, we may be able to give a more informative answer.
\r
78 > For instance when using the python bindings:
\r
79 > In constructor I do
\r
80 > self.db = notmuch.Database(self.db_path)
\r
81 > and there I have a method called periodically that returns:
\r
82 > returns notmuch.Query(self.db, "tag:unread and tag:inbox").count_messages()
\r
84 > When it fails the previous method returns 0 and displays on stdout/stderr;
\r
85 > "A Xapian exception occurred: The revision being read has been
\r
86 > discarded - you should call Xapian::Database::reopen() and retry the
\r
88 > Query string was: tag:unread and tag:inbox"
\r
90 Right, this seems to be a particularly heinous example.
\r
92 Any objections (or better ideas) from fellow developers to something
\r
93 along the lines of the following? It isn't a huge improvement, and I
\r
94 didn't update the other 3 places it's called (or the bindings), but it
\r
95 seems like a step forward. I guess something similar should be done for
\r
96 notmuch_query_count_threads.
\r
98 Alternatively, we could follow unix tradition and return -1 on error.
\r
99 The only argument I can see either way at the moment is that fewer error
\r
100 return styles is better than more.
\r
102 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
103 index 220839b..06228bc 100644
\r
104 --- a/lib/notmuch.h
\r
105 +++ b/lib/notmuch.h
\r
106 @@ -901,8 +901,8 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
107 * If a Xapian exception occurs, this function may return 0 (after
\r
108 * printing a message).
\r
111 -notmuch_query_count_messages (notmuch_query_t *query);
\r
113 +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count);
\r
116 * Return the number of threads matching a search.
\r
117 diff --git a/lib/query.cc b/lib/query.cc
\r
118 index 60ff8bd..a623ea8 100644
\r
121 @@ -508,8 +508,8 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
\r
122 talloc_free (threads);
\r
126 -notmuch_query_count_messages (notmuch_query_t *query)
\r
128 +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count_out)
\r
130 notmuch_database_t *notmuch = query->notmuch;
\r
131 const char *query_string = query->query_string;
\r
132 @@ -562,12 +562,11 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
133 count = mset.get_matches_estimated();
\r
135 } catch (const Xapian::Error &error) {
\r
136 - fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
137 - error.get_msg().c_str());
\r
138 - fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
139 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
144 + *count_out=count;
\r
145 + return NOTMUCH_STATUS_SUCCESS;
\r
149 diff --git a/notmuch-count.c b/notmuch-count.c
\r
150 index 6058f7c..db43959 100644
\r
151 --- a/notmuch-count.c
\r
152 +++ b/notmuch-count.c
\r
153 @@ -71,6 +71,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
155 notmuch_query_t *query;
\r
159 query = notmuch_query_create (notmuch, query_str);
\r
160 if (query == NULL) {
\r
161 @@ -83,7 +84,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
164 case OUTPUT_MESSAGES:
\r
165 - printf ("%u\n", notmuch_query_count_messages (query));
\r
166 + if (notmuch_query_count_messages (query, &count))
\r
168 + printf ("%u\n", count);
\r
170 case OUTPUT_THREADS:
\r
171 printf ("%u\n", notmuch_query_count_threads (query));
\r
172 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
173 index 7c1c809..5b7c0e1 100644
\r
174 --- a/notmuch-reply.c
\r
175 +++ b/notmuch-reply.c
\r
176 @@ -650,8 +650,13 @@ notmuch_reply_format_sprinter(void *ctx,
\r
177 notmuch_messages_t *messages;
\r
178 notmuch_message_t *message;
\r
182 - if (notmuch_query_count_messages (query) != 1) {
\r
183 + if (notmuch_query_count_messages (query, &count)) {
\r
184 + fprintf (stderr, "Error: Xapian exception counting messages.\n");
\r
187 + if (count != 1) {
\r
188 fprintf (stderr, "Error: search term did not match precisely one message.\n");
\r