]> git.notmuchmail.org Git - notmuch/commitdiff
lib: catch error from closed db in n_m_get_message_id
authorDavid Bremner <david@tethera.net>
Tue, 30 Jun 2020 01:14:09 +0000 (22:14 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 4 Jul 2020 00:03:51 +0000 (21:03 -0300)
By catching it at the library top level, we can return an error value.

lib/message.cc
lib/notmuch.h
test/T560-lib-error.sh

index 0fa0eb3aef531237a01a2a19d73847a38fe49fff..b7a64b1c3894c26224e78be165bf58ac445fa777 100644 (file)
@@ -90,6 +90,18 @@ _notmuch_message_destructor (notmuch_message_t *message)
     return 0;
 }
 
     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,
 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));
            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;
        }
     }
     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)
 {
 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);
     if (! message->message_id)
        INTERNAL_ERROR ("Message with document ID of %u has no message ID.\n",
                        message->doc_id);
index ceb5a018e96dae31c3b55f5b366f1f6bf3ccf8e4..0dc89547017a6e5362333e167b0105c9e16c7421 100644 (file)
@@ -1363,9 +1363,8 @@ notmuch_message_get_database (const notmuch_message_t *message);
  * message is valid, (which is until the query from which it derived
  * is destroyed).
  *
  * message is valid, (which is until the query from which it derived
  * is destroyed).
  *
- * This function will not return NULL since Notmuch ensures that every
- * message has a unique message ID, (Notmuch will generate an ID for a
- * message if the original file does not contain one).
+ * This function will return NULL if triggers an unhandled Xapian
+ * exception.
  */
 const char *
 notmuch_message_get_message_id (notmuch_message_t *message);
  */
 const char *
 notmuch_message_get_message_id (notmuch_message_t *message);
index 7284a92b6648c8301fe54418c6b8db37f75092e4..5a5f66b8c193073d26a739b2a13691da6dc3af52 100755 (executable)
@@ -343,7 +343,6 @@ EOF
 
 backup_database
 test_begin_subtest "Handle getting message-id from closed database"
 
 backup_database
 test_begin_subtest "Handle getting message-id from closed database"
-test_subtest_known_broken
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         const char *id2;
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         const char *id2;