From 15c6714cb40ceabe90e83427e2b006dbba6511f6 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Mon, 13 Jan 2014 23:15:13 +0200 Subject: [PATCH] Re: [PATCH 2/2] lib: fix error handling --- 36/6fa2f803fb0c954cb51766fa612b81329651de | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 36/6fa2f803fb0c954cb51766fa612b81329651de diff --git a/36/6fa2f803fb0c954cb51766fa612b81329651de b/36/6fa2f803fb0c954cb51766fa612b81329651de new file mode 100644 index 000000000..6bc5f8d2d --- /dev/null +++ b/36/6fa2f803fb0c954cb51766fa612b81329651de @@ -0,0 +1,142 @@ +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 162AC431FAF + for ; Mon, 13 Jan 2014 13:15:26 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 pby0SulQ9jTb for ; + Mon, 13 Jan 2014 13:15:18 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 0540B431FAE + for ; Mon, 13 Jan 2014 13:15:18 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 8C86F100086; + Mon, 13 Jan 2014 23:15:13 +0200 (EET) +From: Tomi Ollila +To: Tomi Valkeinen , notmuch@notmuchmail.org +Subject: Re: [PATCH 2/2] lib: fix error handling +In-Reply-To: <1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi> +References: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi> + <1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi> +User-Agent: Notmuch/0.17+34~g98b959f (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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: Mon, 13 Jan 2014 21:15:26 -0000 + +On Tue, Nov 19 2013, Tomi Valkeinen wrote: + +> Currently if a Xapian exception happens in notmuch_message_get_header, +> the exception is not caught leading to crash. In +> notmuch_message_get_date the exception is caught, but an internal error +> is raised, again leading to crash. +> +> This patch fixes the error handling by making both functions catch the +> Xapian exceptions, print an error and return NULL or 0. +> +> The 'notmuch->exception_reported' is also set, as is done elsewhere, +> even if I don't really get the idea of that field. + +Althoug this adds the library fprintf() count by one this is important +and consistent fix to the library... + +... whenever we get into consensus how to handle library logging it +is not big deal to convert this also to the new call too. + ++1 + +Tomi + + +> +> Signed-off-by: Tomi Valkeinen +> --- +> lib/message.cc | 34 ++++++++++++++++++++++------------ +> 1 file changed, 22 insertions(+), 12 deletions(-) +> +> diff --git a/lib/message.cc b/lib/message.cc +> index 1b46379..c91f3a5 100644 +> --- a/lib/message.cc +> +++ b/lib/message.cc +> @@ -412,19 +412,27 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message) +> const char * +> notmuch_message_get_header (notmuch_message_t *message, const char *header) +> { +> - std::string value; +> + try { +> + std::string value; +> +> - /* Fetch header from the appropriate xapian value field if +> - * available */ +> - if (strcasecmp (header, "from") == 0) +> - value = message->doc.get_value (NOTMUCH_VALUE_FROM); +> - else if (strcasecmp (header, "subject") == 0) +> - value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT); +> - else if (strcasecmp (header, "message-id") == 0) +> - value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); +> + /* Fetch header from the appropriate xapian value field if +> + * available */ +> + if (strcasecmp (header, "from") == 0) +> + value = message->doc.get_value (NOTMUCH_VALUE_FROM); +> + else if (strcasecmp (header, "subject") == 0) +> + value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT); +> + else if (strcasecmp (header, "message-id") == 0) +> + value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); +> +> - if (!value.empty()) +> - return talloc_strdup (message, value.c_str ()); +> + if (!value.empty()) +> + return talloc_strdup (message, value.c_str ()); +> + +> + } catch (Xapian::Error &error) { +> + fprintf (stderr, "A Xapian exception occurred when reading header: %s\n", +> + error.get_msg().c_str()); +> + message->notmuch->exception_reported = TRUE; +> + return NULL; +> + } +> +> /* Otherwise fall back to parsing the file */ +> _notmuch_message_ensure_message_file (message); +> @@ -766,7 +774,9 @@ notmuch_message_get_date (notmuch_message_t *message) +> try { +> value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP); +> } catch (Xapian::Error &error) { +> - INTERNAL_ERROR ("Failed to read timestamp value from document."); +> + fprintf (stderr, "A Xapian exception occurred when reading date: %s\n", +> + error.get_msg().c_str()); +> + message->notmuch->exception_reported = TRUE; +> return 0; +> } +> +> -- +> 1.8.3.2 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2