]> git.notmuchmail.org Git - notmuch/commitdiff
Fix _notmuch_message_create to catch Xapian DocNotFoundError.
authorCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 12:45:29 +0000 (05:45 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 12:48:52 +0000 (05:48 -0700)
This function is only supposed to be called with a doc_id that
was queried from the database already. So there's an internal
error if no document with that doc_id can be found in the database.

In that case, return NULL.

message.cc

index 9e43af3f0d38df5abbeaf55d0ff0c854322e4910..a2ecda2ddc050f13e340fca36a9530813644f3c5 100644 (file)
@@ -108,6 +108,22 @@ _notmuch_message_destructor (notmuch_message_t *message)
     return 0;
 }
 
     return 0;
 }
 
+/* Create a new notmuch_message_t object for an existing document in
+ * the database.
+ *
+ * Here, 'talloc owner' is an optional talloc context to which the new
+ * message will belong. This allows for the caller to not bother
+ * calling notmuch_message_destroy on the message, and no that all
+ * memory will be reclaimed with 'talloc_owner' is free. The caller
+ * still can call notmuch_message_destroy when finished with the
+ * message if desired.
+ *
+ * The 'talloc_owner' argument can also be NULL, in which case the
+ * caller *is* responsible for calling notmuch_message_destroy.
+ *
+ * If no document exists in the database with document ID of 'doc_id'
+ * then this function returns NULL.
+ */
 notmuch_message_t *
 _notmuch_message_create (const void *talloc_owner,
                         notmuch_database_t *notmuch,
 notmuch_message_t *
 _notmuch_message_create (const void *talloc_owner,
                         notmuch_database_t *notmuch,
@@ -127,7 +143,12 @@ _notmuch_message_create (const void *talloc_owner,
 
     talloc_set_destructor (message, _notmuch_message_destructor);
 
 
     talloc_set_destructor (message, _notmuch_message_destructor);
 
-    message->doc = notmuch->xapian_db->get_document (doc_id);
+    try {
+       message->doc = notmuch->xapian_db->get_document (doc_id);
+    } catch (const Xapian::DocNotFoundError &error) {
+       talloc_free (message);
+       return NULL;
+    }
 
     return message;
 }
 
     return message;
 }