aboutsummaryrefslogtreecommitdiff
path: root/lib/message.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-06-29 22:14:09 -0300
committerDavid Bremner <david@tethera.net>2020-07-03 21:03:51 -0300
commit87d462a20423a25eaf4b54a90bfd538dd93da675 (patch)
treebd54efde24ef7e3a3c8c1ffba9779fc54345b2bf /lib/message.cc
parent2c17327ee5c428e3d52a188b0433a130b4684438 (diff)
lib: catch error from closed db in n_m_get_message_id
By catching it at the library top level, we can return an error value.
Diffstat (limited to 'lib/message.cc')
-rw-r--r--lib/message.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 0fa0eb3a..b7a64b1c 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -90,6 +90,18 @@ _notmuch_message_destructor (notmuch_message_t *message)
return 0;
}
+#define LOG_XAPIAN_EXCEPTION(message, error) _log_xapian_exception (__location__, message, error)
+
+static void
+_log_xapian_exception (const char *where, notmuch_message_t *message, const Xapian::Error error) {
+ notmuch_database_t *notmuch = notmuch_message_get_database (message);
+ _notmuch_database_log (notmuch,
+ "A Xapian exception occurred %s retrieving %s : %s\n",
+ where,
+ error.get_msg ().c_str ());
+ notmuch->exception_reported = true;
+}
+
static notmuch_message_t *
_notmuch_message_create_for_document (const void *talloc_owner,
notmuch_database_t *notmuch,
@@ -447,9 +459,6 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message, void *field)
if (status != NOTMUCH_STATUS_SUCCESS)
INTERNAL_ERROR ("unhandled error from notmuch_database_reopen: %s\n",
notmuch_status_to_string (status));
- } catch (const Xapian::Error &error) {
- INTERNAL_ERROR ("A Xapian exception occurred fetching message metadata: %s\n",
- error.get_msg ().c_str ());
}
}
message->last_view = message->notmuch->view;
@@ -507,7 +516,13 @@ _notmuch_message_get_doc_id (notmuch_message_t *message)
const char *
notmuch_message_get_message_id (notmuch_message_t *message)
{
- _notmuch_message_ensure_metadata (message, message->message_id);
+ try {
+ _notmuch_message_ensure_metadata (message, message->message_id);
+ } catch (const Xapian::Error &error) {
+ LOG_XAPIAN_EXCEPTION (message, error);
+ return NULL;
+ }
+
if (! message->message_id)
INTERNAL_ERROR ("Message with document ID of %u has no message ID.\n",
message->doc_id);