aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar Tomi Valkeinen <tomi.valkeinen@iki.fi>2013-11-19 07:10:31 +0200
committerGravatar David Bremner <david@tethera.net>2014-01-18 14:47:35 -0400
commit075d53dde5446fefe121e548156901cf72f7f8e3 (patch)
tree1d92f862716e05da29f159dbea447962db35c84b /lib
parent40a3bf7e68338d34d10ddc77f746af53ff6d3182 (diff)
lib: fix error handling
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/message.cc34
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 1b463795..c91f3a59 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;
}