--- /dev/null
+Return-Path: <tomi.valkeinen@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id CC151431FC9\r
+ for <notmuch@notmuchmail.org>; Mon, 18 Nov 2013 21:19:22 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id zykYf31E3dd2 for <notmuch@notmuchmail.org>;\r
+ Mon, 18 Nov 2013 21:19:15 -0800 (PST)\r
+Received: from mail-la0-f49.google.com (mail-la0-f49.google.com\r
+ [209.85.215.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 874CC431FC2\r
+ for <notmuch@notmuchmail.org>; Mon, 18 Nov 2013 21:19:15 -0800 (PST)\r
+Received: by mail-la0-f49.google.com with SMTP id er20so5564241lab.22\r
+ for <notmuch@notmuchmail.org>; Mon, 18 Nov 2013 21:19:14 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=sender:from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=fLfDEb0IGpEx/WJixURzhGCCKhddz8tMjKFxA3UzbJA=;\r
+ b=xQtMR/kDL4gQ+YppHemzr4wScSZcqeJq/SEidRcjvxQ0dynDh94j9h2xSWd9/Qz4f5\r
+ KH/AYVu8LFzxQvw0tvdQs4FO9aGE05fALmFK29NaT/h3dHXndX9A6+7uNol9iTCC4UCG\r
+ DgLxMigVG32Pj4GqFom3MfUiHUOmP+ZvIyanQyo7cUIEBuNKMAA3Tw+1jF2gg2yNGFd5\r
+ UIsh9gI78plS9NQ/XeVXT31EZbkCjeVhZXjxmVq0tS8eDry2C6T3n6CLvQKlkou/pgbz\r
+ KuvRo570Rj5eBd8kenyzG3iqqjUrL2hGoLfOb5SgOjwdCogOu4rtD5jjXLJk3dw3DwQ+\r
+ Tqiw==\r
+X-Received: by 10.112.134.3 with SMTP id pg3mr16300431lbb.11.1384837880548;\r
+ Mon, 18 Nov 2013 21:11:20 -0800 (PST)\r
+Received: from deskari.tieu.ti.com (a91-156-160-115.elisa-laajakaista.fi.\r
+ [91.156.160.115])\r
+ by mx.google.com with ESMTPSA id m5sm11942484laj.4.2013.11.18.21.11.18\r
+ for <multiple recipients>\r
+ (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\r
+ Mon, 18 Nov 2013 21:11:19 -0800 (PST)\r
+Sender: Tomi Valkeinen <tomi.valkeinen@gmail.com>\r
+From: Tomi Valkeinen <tomi.valkeinen@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] lib: fix error handling\r
+Date: Tue, 19 Nov 2013 07:10:31 +0200\r
+Message-Id: <1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi>\r
+X-Mailer: git-send-email 1.8.3.2\r
+In-Reply-To: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi>\r
+References: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 19 Nov 2013 05:19:22 -0000\r
+\r
+Currently if a Xapian exception happens in notmuch_message_get_header,\r
+the exception is not caught leading to crash. In\r
+notmuch_message_get_date the exception is caught, but an internal error\r
+is raised, again leading to crash.\r
+\r
+This patch fixes the error handling by making both functions catch the\r
+Xapian exceptions, print an error and return NULL or 0.\r
+\r
+The 'notmuch->exception_reported' is also set, as is done elsewhere,\r
+even if I don't really get the idea of that field.\r
+\r
+Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>\r
+---\r
+ lib/message.cc | 34 ++++++++++++++++++++++------------\r
+ 1 file changed, 22 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 1b46379..c91f3a5 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -412,19 +412,27 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)\r
+ const char *\r
+ notmuch_message_get_header (notmuch_message_t *message, const char *header)\r
+ {\r
+- std::string value;\r
++ try {\r
++ std::string value;\r
+ \r
+- /* Fetch header from the appropriate xapian value field if\r
+- * available */\r
+- if (strcasecmp (header, "from") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_FROM);\r
+- else if (strcasecmp (header, "subject") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);\r
+- else if (strcasecmp (header, "message-id") == 0)\r
+- value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);\r
++ /* Fetch header from the appropriate xapian value field if\r
++ * available */\r
++ if (strcasecmp (header, "from") == 0)\r
++ value = message->doc.get_value (NOTMUCH_VALUE_FROM);\r
++ else if (strcasecmp (header, "subject") == 0)\r
++ value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT);\r
++ else if (strcasecmp (header, "message-id") == 0)\r
++ value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID);\r
+ \r
+- if (!value.empty())\r
+- return talloc_strdup (message, value.c_str ());\r
++ if (!value.empty())\r
++ return talloc_strdup (message, value.c_str ());\r
++\r
++ } catch (Xapian::Error &error) {\r
++ fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",\r
++ error.get_msg().c_str());\r
++ message->notmuch->exception_reported = TRUE;\r
++ return NULL;\r
++ }\r
+ \r
+ /* Otherwise fall back to parsing the file */\r
+ _notmuch_message_ensure_message_file (message);\r
+@@ -766,7 +774,9 @@ notmuch_message_get_date (notmuch_message_t *message)\r
+ try {\r
+ value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);\r
+ } catch (Xapian::Error &error) {\r
+- INTERNAL_ERROR ("Failed to read timestamp value from document.");\r
++ fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",\r
++ error.get_msg().c_str());\r
++ message->notmuch->exception_reported = TRUE;\r
+ return 0;\r
+ }\r
+ \r
+-- \r
+1.8.3.2\r
+\r