From: Matt Date: Thu, 18 Dec 2014 21:10:26 +0000 (+0100) Subject: Re: Python bindings and Xapian exceptions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=aee5884c1d32450709de94654e072bb457e4c0dd;p=notmuch-archives.git Re: Python bindings and Xapian exceptions --- diff --git a/0f/149a7f622c9ac50e739834c9723529c17d8995 b/0f/149a7f622c9ac50e739834c9723529c17d8995 new file mode 100644 index 000000000..4366f9252 --- /dev/null +++ b/0f/149a7f622c9ac50e739834c9723529c17d8995 @@ -0,0 +1,210 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B1D23431FC7 + for ; Thu, 18 Dec 2014 13:10:30 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id ZDBroLNwqWOw for ; + Thu, 18 Dec 2014 13:10:27 -0800 (PST) +Received: from mail-qa0-f43.google.com (mail-qa0-f43.google.com + [209.85.216.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 62734431FD6 + for ; Thu, 18 Dec 2014 13:10:27 -0800 (PST) +Received: by mail-qa0-f43.google.com with SMTP id x12so1390790qac.2 + for ; Thu, 18 Dec 2014 13:10:26 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=mime-version:in-reply-to:references:date:message-id:subject:from:to + :cc:content-type; + bh=IyLrC/NcMV8LYUuwj0Vj1Re95F1n2cBmqjQuFmcmLRg=; + b=Yi4XWadQDqY+ijh77nB6ghbWTivpmH+M1JHB6pT89usy27kNC95Rf5pkc1Txvw7uLJ + c184XYp/qeZ+B4Sf+OP9C2l/H2OsPfiJXb9DvsAFvxm6BbiSmpzTj9nKx83ytX3K+R1I + NquT5I8AAbezEYgP2DU6xpscNASzQawU3rvcIhLcEU+FcBkrCoZnxguS1ktBrPnVyPAS + BYEvLEKaCz7Gkt+hShVPZeBooFW5sFQiK5plHyiy1c8Gkx0/z2HobCKdFUITKbq+2CBx + HbC/M2JRNAWdAM9TCj6OoyNsaGXQWHc+K7ZC5w9uTpHBho8M/2lKy5erSaOtoCOeyi5k + Fyjg== +MIME-Version: 1.0 +X-Received: by 10.224.172.4 with SMTP id j4mr7788637qaz.58.1418937026639; Thu, + 18 Dec 2014 13:10:26 -0800 (PST) +Received: by 10.96.77.105 with HTTP; Thu, 18 Dec 2014 13:10:26 -0800 (PST) +In-Reply-To: <87fvcg6n06.fsf@maritornes.cs.unb.ca> +References: <87k4q7s43v.fsf@ut.hh.sledj.net> <878w6gis5g.fsf@SSpaeth.de> + <871v70ril7.fsf@yoom.home.cworth.org> <871v70z0y5.fsf@SSpaeth.de> + + <87iohc7iiz.fsf@maritornes.cs.unb.ca> + + <87fvcg6n06.fsf@maritornes.cs.unb.ca> +Date: Thu, 18 Dec 2014 22:10:26 +0100 +Message-ID: + +Subject: Re: Python bindings and Xapian exceptions +From: Matt +To: David Bremner +Content-Type: text/plain; charset=UTF-8 +X-Mailman-Approved-At: Thu, 18 Dec 2014 21:43:25 -0800 +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 18 Dec 2014 21:10:30 -0000 + +For now, as a workaround, I open the db, do my request, close it and +repeat the process 5/10 sec later. I hope it does not add to much +overhead ?! Anyway, it owuld be nice to have this fixed in one way or +another. + +Thanks for your answer David. +Best regards + +2014-12-16 9:02 GMT+01:00 David Bremner : +> Matt writes: +> +>> 2014-12-15 21:41 GMT+01:00 David Bremner : +>>> Matt writes: +>>> +>>>>> > But for exceptions in general, yes the notmuch library does need to be +>>>>> > fixed to allow the caller of functions to distinguish between things +>>>>> > like "no matches found" and "an exception occurred, so it's unknown if +>>>>> > any messages match the search". That's a general class of library +>>>>> > interface bugs that all need to be fixed. +>>>> +>>>> I 've also hit this *API bug* and was wondering if a fix had been done since +>>>> then (I use notmuch 0.17) ? I found nothing on http://notmuchmail.org/news/ +>>> +>>> Can you be more specific? I'd say in general no thorough overhaul of +>>> error handling has happened, but if you can tell us what particular +>>> libnotmuch function (or the equivalient python binding) you are having +>>> trouble with, we may be able to give a more informative answer. +>>> +>> +>> For instance when using the python bindings: +>> In constructor I do +>> self.db = notmuch.Database(self.db_path) +>> and there I have a method called periodically that returns: +>> returns notmuch.Query(self.db, "tag:unread and tag:inbox").count_messages() +>> +>> When it fails the previous method returns 0 and displays on stdout/stderr; +>> "A Xapian exception occurred: The revision being read has been +>> discarded - you should call Xapian::Database::reopen() and retry the +>> operation +>> Query string was: tag:unread and tag:inbox" +> +> Right, this seems to be a particularly heinous example. +> +> Any objections (or better ideas) from fellow developers to something +> along the lines of the following? It isn't a huge improvement, and I +> didn't update the other 3 places it's called (or the bindings), but it +> seems like a step forward. I guess something similar should be done for +> notmuch_query_count_threads. +> +> Alternatively, we could follow unix tradition and return -1 on error. +> The only argument I can see either way at the moment is that fewer error +> return styles is better than more. +> +> diff --git a/lib/notmuch.h b/lib/notmuch.h +> index 220839b..06228bc 100644 +> --- a/lib/notmuch.h +> +++ b/lib/notmuch.h +> @@ -901,8 +901,8 @@ notmuch_threads_destroy (notmuch_threads_t *threads); +> * If a Xapian exception occurs, this function may return 0 (after +> * printing a message). +> */ +> -unsigned +> -notmuch_query_count_messages (notmuch_query_t *query); +> +notmuch_status_t +> +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count); +> +> /** +> * Return the number of threads matching a search. +> diff --git a/lib/query.cc b/lib/query.cc +> index 60ff8bd..a623ea8 100644 +> --- a/lib/query.cc +> +++ b/lib/query.cc +> @@ -508,8 +508,8 @@ notmuch_threads_destroy (notmuch_threads_t *threads) +> talloc_free (threads); +> } +> +> -unsigned +> -notmuch_query_count_messages (notmuch_query_t *query) +> +notmuch_status_t +> +notmuch_query_count_messages (notmuch_query_t *query, unsigned *count_out) +> { +> notmuch_database_t *notmuch = query->notmuch; +> const char *query_string = query->query_string; +> @@ -562,12 +562,11 @@ notmuch_query_count_messages (notmuch_query_t *query) +> count = mset.get_matches_estimated(); +> +> } catch (const Xapian::Error &error) { +> - fprintf (stderr, "A Xapian exception occurred: %s\n", +> - error.get_msg().c_str()); +> - fprintf (stderr, "Query string was: %s\n", query->query_string); +> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; +> } +> - +> - return count; +> + +> + *count_out=count; +> + return NOTMUCH_STATUS_SUCCESS; +> } +> +> unsigned +> diff --git a/notmuch-count.c b/notmuch-count.c +> index 6058f7c..db43959 100644 +> --- a/notmuch-count.c +> +++ b/notmuch-count.c +> @@ -71,6 +71,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str, +> { +> notmuch_query_t *query; +> size_t i; +> + unsigned count; +> +> query = notmuch_query_create (notmuch, query_str); +> if (query == NULL) { +> @@ -83,7 +84,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str, +> +> switch (output) { +> case OUTPUT_MESSAGES: +> - printf ("%u\n", notmuch_query_count_messages (query)); +> + if (notmuch_query_count_messages (query, &count)) +> + return 1; +> + printf ("%u\n", count); +> break; +> case OUTPUT_THREADS: +> printf ("%u\n", notmuch_query_count_threads (query)); +> diff --git a/notmuch-reply.c b/notmuch-reply.c +> index 7c1c809..5b7c0e1 100644 +> --- a/notmuch-reply.c +> +++ b/notmuch-reply.c +> @@ -650,8 +650,13 @@ notmuch_reply_format_sprinter(void *ctx, +> notmuch_messages_t *messages; +> notmuch_message_t *message; +> mime_node_t *node; +> + unsigned count; +> +> - if (notmuch_query_count_messages (query) != 1) { +> + if (notmuch_query_count_messages (query, &count)) { +> + fprintf (stderr, "Error: Xapian exception counting messages.\n"); +> + return 1; +> + } +> + if (count != 1) { +> fprintf (stderr, "Error: search term did not match precisely one message.\n"); +> return 1; +> }