aboutsummaryrefslogtreecommitdiff
path: root/lib/thread.cc
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2025-07-28 16:26:56 +0200
committerDavid Bremner <david@tethera.net>2025-08-04 10:43:35 -0300
commit11d373b4fd05f5409bf5c49459fe141d2235f7f5 (patch)
treebb194cb1fe5bce7696f7536e883d7acebe7cdab3 /lib/thread.cc
parent32af882648325ba1a24f031c0d2728b2553a5e6e (diff)
lib: add notmuch_threads_status()
While a number of errors can happen when iterating over threads (DatabaseModifiedError, memory allocation errors, etc.), the API currently cannot signal them to the caller, and either triggers an internal error (aborting the caller) or returns NULL from notmuch_threads_get() with no information on what actually went wrong. Add a new public function notmuch_threads_status() - similar to previously added notmuch_messages_status() - that allows propagating those errors to the caller. Use this to remove the INTERNAL_ERROR() in _notmuch_thread_create() (triggered by T642). Fixes: https://github.com/pazz/alot/issues/1460 Amended-By: db. Resolved whitespace disagreement between emacs and uncrustify in favour of uncrustify.
Diffstat (limited to 'lib/thread.cc')
-rw-r--r--lib/thread.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/thread.cc b/lib/thread.cc
index 168a9e8b..75b0f188 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -544,16 +544,17 @@ _resolve_thread_relationships (notmuch_thread_t *thread)
*
* Here, 'ctx' is talloc context for the resulting thread object.
*
- * This function returns NULL in the case of any error.
+ * This function write NULL in the case of any error.
*/
-notmuch_thread_t *
+notmuch_private_status_t
_notmuch_thread_create (void *ctx,
notmuch_database_t *notmuch,
unsigned int seed_doc_id,
notmuch_doc_id_set_t *match_set,
notmuch_string_list_t *exclude_terms,
notmuch_exclude_t omit_excluded,
- notmuch_sort_t sort)
+ notmuch_sort_t sort,
+ notmuch_thread_t **pthread)
{
void *local = talloc_new (ctx);
notmuch_thread_t *thread = NULL;
@@ -564,11 +565,13 @@ _notmuch_thread_create (void *ctx,
notmuch_messages_t *messages;
notmuch_message_t *message;
- notmuch_status_t status;
+ notmuch_private_status_t status;
- seed_message = _notmuch_message_create (local, notmuch, seed_doc_id, NULL);
- if (! seed_message)
- INTERNAL_ERROR ("Thread seed message %u does not exist", seed_doc_id);
+ *pthread = NULL;
+
+ seed_message = _notmuch_message_create (local, notmuch, seed_doc_id, &status);
+ if (status)
+ return status;
thread_id = notmuch_message_get_thread_id (seed_message);
thread_id_query_string = talloc_asprintf (local, "thread:%s", thread_id);
@@ -623,7 +626,7 @@ _notmuch_thread_create (void *ctx,
* oldest or newest subject is desired. */
notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
- status = notmuch_query_search_messages (thread_id_query, &messages);
+ status = (notmuch_private_status_t) notmuch_query_search_messages (thread_id_query, &messages);
if (status)
goto DONE;
@@ -656,10 +659,13 @@ _notmuch_thread_create (void *ctx,
/* Commit to returning thread. */
(void) talloc_steal (ctx, thread);
+ *pthread = thread;
DONE:
talloc_free (local);
- return thread;
+ if (! *pthread && ! status)
+ status = NOTMUCH_PRIVATE_STATUS_OUT_OF_MEMORY;
+ return status;
}
notmuch_messages_t *