diff options
author | Carl Worth <cworth@cworth.org> | 2009-10-23 05:45:29 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-10-23 05:48:52 -0700 |
commit | 69b25a75ec8f4a8b27fe25f234a39a7e67287d36 (patch) | |
tree | 28b4ba5f75d14f67f2c223982d79ff5bd64d01cd /message.cc | |
parent | 17548e314a8f190765ca714d626068c5afef2cb4 (diff) |
Fix _notmuch_message_create to catch Xapian DocNotFoundError.
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.
Diffstat (limited to 'message.cc')
-rw-r--r-- | message.cc | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -108,6 +108,22 @@ _notmuch_message_destructor (notmuch_message_t *message) 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, @@ -127,7 +143,12 @@ _notmuch_message_create (const void *talloc_owner, 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; } |