]> git.cworth.org Git - notmuch/commitdiff
lib: return NOTMUCH_STATUS_OPERATION_INVALIDATED where appropriate master
authorAnton Khirnov <anton@khirnov.net>
Wed, 6 Aug 2025 05:43:06 +0000 (07:43 +0200)
committerDavid Bremner <david@tethera.net>
Sat, 9 Aug 2025 10:12:23 +0000 (07:12 -0300)
The overall goal is to allow clients to restart operations in
situations where that is the response recommended by the underlying
Xapian library.

Amended-by: db, added above explanation
lib/add-message.cc
lib/config.cc
lib/database.cc
lib/directory.cc
lib/message-property.cc
lib/message.cc
lib/notmuch-private.h
lib/parse-sexp.cc
lib/query.cc

index b16748fda20ebf4128f4e8fd78f4a66f9c9a83c2..3942cab1376836036a9293f0b6365da9c31d139a 100644 (file)
@@ -565,7 +565,7 @@ notmuch_database_index_file (notmuch_database_t *notmuch,
        _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       ret = _notmuch_xapian_error ();
        goto DONE;
     }
 
        goto DONE;
     }
 
index 6cc5986989969c3edc9de5d144ca37ef184c4c30..8fbd7336ce9ec4e3f9b811233022189a69ae8a3c 100644 (file)
@@ -75,7 +75,7 @@ notmuch_database_set_config (notmuch_database_t *notmuch,
     try {
        notmuch->writable_xapian_db->set_metadata (CONFIG_PREFIX + key, value);
     } catch (const Xapian::Error &error) {
     try {
        notmuch->writable_xapian_db->set_metadata (CONFIG_PREFIX + key, value);
     } catch (const Xapian::Error &error) {
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "Error: A Xapian exception occurred setting metadata: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "Error: A Xapian exception occurred setting metadata: %s\n",
                               error.get_msg ().c_str ());
@@ -99,7 +99,7 @@ _metadata_value (notmuch_database_t *notmuch,
     try {
        value = notmuch->xapian_db->get_metadata (CONFIG_PREFIX + key);
     } catch (const Xapian::Error &error) {
     try {
        value = notmuch->xapian_db->get_metadata (CONFIG_PREFIX + key);
     } catch (const Xapian::Error &error) {
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "Error: A Xapian exception occurred getting metadata: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "Error: A Xapian exception occurred getting metadata: %s\n",
                               error.get_msg ().c_str ());
@@ -164,7 +164,7 @@ notmuch_database_get_config_list (notmuch_database_t *notmuch,
                               "A Xapian exception occurred getting metadata iterator: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
                               "A Xapian exception occurred getting metadata iterator: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
     }
 
     *out = list;
     }
 
     *out = list;
index 8f687eee82cc189af1b84edadaf757c41b79a6c2..eb7ed388d53a95f14afcd77c571a727474d262ed 100644 (file)
@@ -468,7 +468,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        *message_ret = NULL;
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        *message_ret = NULL;
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 }
 
     }
 }
 
@@ -520,7 +520,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
             * transaction, ALL pending changes will be discarded */
            notmuch->xapian_db->close ();
        } catch (const Xapian::Error &error) {
             * transaction, ALL pending changes will be discarded */
            notmuch->xapian_db->close ();
        } catch (const Xapian::Error &error) {
-           status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+           status = _notmuch_xapian_error ();
            if (! notmuch->exception_reported) {
                _notmuch_database_log (notmuch,
                                       "Error: A Xapian exception occurred closing database: %s\n",
            if (! notmuch->exception_reported) {
                _notmuch_database_log (notmuch,
                                       "Error: A Xapian exception occurred closing database: %s\n",
@@ -689,7 +689,7 @@ notmuch_database_compact_db (notmuch_database_t *notmuch,
                                     compactor);
     } catch (const Xapian::Error &error) {
        _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg ().c_str ());
                                     compactor);
     } catch (const Xapian::Error &error) {
        _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg ().c_str ());
-       ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       ret = _notmuch_xapian_error ();
        goto DONE;
     }
 
        goto DONE;
     }
 
@@ -1127,7 +1127,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
        _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
   DONE:
     }
 
   DONE:
@@ -1169,7 +1169,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)
        _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     if (notmuch->atomic_dirty) {
     }
 
     if (notmuch->atomic_dirty) {
@@ -1417,7 +1417,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,
        _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
        _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
     }
     return status;
 }
     }
     return status;
 }
@@ -1517,7 +1517,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
                               "Error: A Xapian exception occurred finding message by filename: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
                               "Error: A Xapian exception occurred finding message by filename: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
     }
 
   DONE:
     }
 
   DONE:
index 5cf64d7fc4021748b8d686cf36ed758741161db0..dea0a225de6f4ec4a892daeaf0a67644a26bdfd5 100644 (file)
@@ -206,7 +206,7 @@ _notmuch_directory_find_or_create (notmuch_database_t *notmuch,
        notmuch->exception_reported = true;
        notmuch_directory_destroy (directory);
        directory = NULL;
        notmuch->exception_reported = true;
        notmuch_directory_destroy (directory);
        directory = NULL;
-       *status_ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       *status_ret = _notmuch_xapian_error ();
     }
 
   DONE:
     }
 
   DONE:
@@ -247,7 +247,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
                               "A Xapian exception occurred setting directory mtime: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
                               "A Xapian exception occurred setting directory mtime: %s.\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     return NOTMUCH_STATUS_SUCCESS;
     }
 
     return NOTMUCH_STATUS_SUCCESS;
@@ -321,7 +321,7 @@ notmuch_directory_delete (notmuch_directory_t *directory)
                               "A Xapian exception occurred deleting directory entry: %s.\n",
                               error.get_msg ().c_str ());
        directory->notmuch->exception_reported = true;
                               "A Xapian exception occurred deleting directory entry: %s.\n",
                               error.get_msg ().c_str ());
        directory->notmuch->exception_reported = true;
-       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error ();
     }
     notmuch_directory_destroy (directory);
 
     }
     notmuch_directory_destroy (directory);
 
index 7f5203403723d3514e8d85f738d43b546adcabe7..f876e5ef880842c58a8b9174545510a1012af43c 100644 (file)
@@ -104,7 +104,7 @@ _notmuch_message_modify_property (notmuch_message_t *message, const char *key, c
            private_status = _notmuch_message_add_term (message, "property", term);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
            private_status = _notmuch_message_add_term (message, "property", term);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     if (private_status)
     }
 
     if (private_status)
@@ -153,7 +153,7 @@ _notmuch_message_remove_all_properties (notmuch_message_t *message, const char *
        _notmuch_message_remove_terms (message, term_prefix);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
        _notmuch_message_remove_terms (message, term_prefix);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     if (! _notmuch_message_frozen (message))
     }
 
     if (! _notmuch_message_frozen (message))
index ea815efeafceb31c10ccf2bc191c308d7a6f0b02..71723d2ba9aeeea8b39576c53486f9ac1202df49 100644 (file)
@@ -297,7 +297,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
                               "A Xapian exception occurred creating message: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
                               "A Xapian exception occurred creating message: %s\n",
                               error.get_msg ().c_str ());
        notmuch->exception_reported = true;
-       *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
+       *status_ret = _notmuch_xapian_error_private ();
        return NULL;
     }
 
        return NULL;
     }
 
@@ -1211,7 +1211,7 @@ notmuch_message_get_flag_st (notmuch_message_t *message,
            _notmuch_message_ensure_metadata (message, NULL);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
            _notmuch_message_ensure_metadata (message, NULL);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     *is_set = NOTMUCH_TEST_BIT (message->flags, flag);
     }
 
     *is_set = NOTMUCH_TEST_BIT (message->flags, flag);
@@ -1433,7 +1433,7 @@ _notmuch_message_delete (notmuch_message_t *message)
        }
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
        }
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
     if (count > 0) {
        /* reintroduce a ghost in its place because there are still
     }
     if (count > 0) {
        /* reintroduce a ghost in its place because there are still
@@ -1464,7 +1464,7 @@ _notmuch_message_delete (notmuch_message_t *message)
            }
        } catch (Xapian::Error &error) {
            LOG_XAPIAN_EXCEPTION (message, error);
            }
        } catch (Xapian::Error &error) {
            LOG_XAPIAN_EXCEPTION (message, error);
-           return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+           return _notmuch_xapian_error ();
        }
 
     }
        }
 
     }
@@ -1534,7 +1534,7 @@ _notmuch_message_add_term (notmuch_message_t *message,
        _notmuch_message_invalidate_metadata (message, prefix_name);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
        _notmuch_message_invalidate_metadata (message, prefix_name);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error_private ();
     }
 
   DONE:
     }
 
   DONE:
@@ -1645,7 +1645,7 @@ _notmuch_message_has_term (notmuch_message_t *message,
            ! strcmp ((*i).c_str (), term))
            out = true;
     } catch (Xapian::Error &error) {
            ! strcmp ((*i).c_str (), term))
            out = true;
     } catch (Xapian::Error &error) {
-       status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
+       status = _notmuch_xapian_error_private ();
     }
     talloc_free (term);
 
     }
     talloc_free (term);
 
@@ -1682,7 +1682,7 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)
 
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
 
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     return NOTMUCH_STATUS_SUCCESS;
     }
 
     return NOTMUCH_STATUS_SUCCESS;
@@ -1716,7 +1716,7 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)
            _notmuch_message_sync (message);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
            _notmuch_message_sync (message);
     } catch (Xapian::Error &error) {
        LOG_XAPIAN_EXCEPTION (message, error);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     return NOTMUCH_STATUS_SUCCESS;
     }
 
     return NOTMUCH_STATUS_SUCCESS;
index 89ab5397c007921bad28a1610bd69fb7e892abf5..ba07083b8594f4b6321c515286b44285b021a536 100644 (file)
@@ -746,6 +746,9 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
 NOTMUCH_END_DECLS
 
 #ifdef __cplusplus
+
+#include <xapian.h>
+
 /* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
  * C++. In talloc_steal, an explicit cast is provided for type safety
  * in some GCC versions. Otherwise, a cast is required. Provide a
 /* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
  * C++. In talloc_steal, an explicit cast is provided for type safety
  * in some GCC versions. Otherwise, a cast is required. Provide a
@@ -767,6 +770,27 @@ _notmuch_talloc_steal (const void *new_ctx, const T *ptr)
 #else
 #define NODISCARD /**/
 #endif
 #else
 #define NODISCARD /**/
 #endif
+
+/* Should be called from a Xapian::Error exception handler to map it
+ * into a notmuch status code. */
+static inline notmuch_private_status_t
+_notmuch_xapian_error_private (void)
+{
+    try {
+       throw;
+    } catch (const Xapian::DatabaseModifiedError& _e) {
+       return NOTMUCH_PRIVATE_STATUS_OPERATION_INVALIDATED;
+    } catch (const Xapian::Error& _e) {
+       return NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
+    }
+}
+
+static inline notmuch_status_t
+_notmuch_xapian_error (void)
+{
+    return COERCE_STATUS (_notmuch_xapian_error_private (),
+                         "mapping Xapian exception");
+}
 #endif
 
 #endif
 #endif
 
 #endif
index 930888e9535ed2271936e9c74653343d182c4a5a..b61f020c2f828effe0e141467719bee0d04887da 100644 (file)
@@ -366,7 +366,7 @@ _sexp_parse_infix (notmuch_database_t *notmuch, const sexp_t *sx, Xapian::Query
                                          "Query string was: %s\n",
                                          sx->val);
            notmuch->exception_reported = true;
                                          "Query string was: %s\n",
                                          sx->val);
            notmuch->exception_reported = true;
-           return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+           return _notmuch_xapian_error ();
        }
     }
     return NOTMUCH_STATUS_SUCCESS;
        }
     }
     return NOTMUCH_STATUS_SUCCESS;
index 1761cdc9ca3ae0e25269e04c04eb72e1c5ea3b02..f93c26b388dc6863962c923771e07c04d3ad5983 100644 (file)
@@ -206,7 +206,7 @@ _notmuch_query_string_to_xapian_query (notmuch_database_t *notmuch,
        }
 
        msg = error.get_msg ();
        }
 
        msg = error.get_msg ();
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
     return NOTMUCH_STATUS_SUCCESS;
 }
     }
     return NOTMUCH_STATUS_SUCCESS;
 }
@@ -465,7 +465,7 @@ _notmuch_query_search_documents (notmuch_query_t *query,
 
        notmuch->exception_reported = true;
        talloc_free (messages);
 
        notmuch->exception_reported = true;
        talloc_free (messages);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 }
 
     }
 }
 
@@ -786,7 +786,7 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign
        _notmuch_database_log_append (notmuch,
                                      "Query string was: %s\n",
                                      query->query_string);
        _notmuch_database_log_append (notmuch,
                                      "Query string was: %s\n",
                                      query->query_string);
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     *count_out = count;
     }
 
     *count_out = count;
@@ -893,7 +893,7 @@ _notmuch_query_expand (notmuch_database_t *notmuch, const char *field, Xapian::Q
                               "A Xapian exception occurred expanding query: %s\n",
                               error.get_msg ().c_str ());
        msg = error.get_msg ();
                               "A Xapian exception occurred expanding query: %s\n",
                               error.get_msg ().c_str ());
        msg = error.get_msg ();
-       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+       return _notmuch_xapian_error ();
     }
 
     return NOTMUCH_STATUS_SUCCESS;
     }
 
     return NOTMUCH_STATUS_SUCCESS;