unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Valkeinen <tomi.valkeinen@iki.fi>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/2] lib: fix error handling
Date: Tue, 19 Nov 2013 07:10:31 +0200	[thread overview]
Message-ID: <1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi> (raw)
In-Reply-To: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi>

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.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
---
 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

  reply	other threads:[~2013-11-19  5:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19  5:10 [PATCH 1/2] fix compilation without emacs Tomi Valkeinen
2013-11-19  5:10 ` Tomi Valkeinen [this message]
2014-01-13 21:15   ` [PATCH 2/2] lib: fix error handling Tomi Ollila
2014-01-15 13:45     ` David Bremner
2014-01-19  0:09   ` David Bremner
2013-11-19 10:43 ` [PATCH 1/2] fix compilation without emacs Tomi Ollila
2013-11-19 11:02   ` Tomi Valkeinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi \
    --to=tomi.valkeinen@iki.fi \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).