lib: handle DatabaseModifiedError in _notmuch_message_create master
authorAnton Khirnov <anton@khirnov.net>
Mon, 7 Jul 2025 12:27:06 +0000 (14:27 +0200)
committerDavid Bremner <david@tethera.net>
Thu, 24 Jul 2025 10:30:58 +0000 (07:30 -0300)
commitf375ea1add121c428f261473512831a169dfe335
treee294f60da65ba4f76e9f53d2afcd118b6b157cb6
parent4547ae5aa8fc7fd5d05da801c9fa9c055d39636f
lib: handle DatabaseModifiedError in _notmuch_message_create

If an open database is modified sufficiently by other callers, the open
instance becomes invalid and operations on it throw
DatabaseModifiedError. Per Xapian documentation, the caller is then
supposed to reopen the database and restart the query. This exception is
currently not handled in _notmuch_message_create(), leading to the
default handler abort()ing the process.

Catch this exception in _notmuch_message_create() and return an error
instead of crashing. Since the entire query becomes invalid - including
results that have already been read by the caller - this situation
cannot be handled by libnotmuch transparently. A new public function -
notmuch_messages_status() - is added to allow the callers to check
whether the messages iterator was exhausted or terminated early due to
a runtime error. This also allows memory allocation failure to be
signalled to the caller.

Amended-By: David Bremner <david@tethera.net>
            [replace use of notmuch_messages_valid]
lib/database.cc
lib/message.cc
lib/messages.c
lib/notmuch-private.h
lib/notmuch.h
lib/query.cc
test/T641-database-modified-messages.sh