--- Applied review comments: * missing spaces between function name and () * renamed _notmuch_xapian_errorp to _notmuch_xapian_error_private; added a comment about what it does --- lib/add-message.cc | 2 +- lib/config.cc | 6 +++--- lib/database.cc | 14 +++++++------- lib/directory.cc | 6 +++--- lib/message-property.cc | 4 ++-- lib/message.cc | 16 ++++++++-------- lib/notmuch-private.h | 19 +++++++++++++++++++ lib/parse-sexp.cc | 2 +- lib/query.cc | 8 ++++---- 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/lib/add-message.cc b/lib/add-message.cc index b16748fd..48f37ba3 100644 --- a/lib/add-message.cc +++ b/lib/add-message.cc @@ -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; - ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + ret = _notmuch_xapian_error (error); goto DONE; } diff --git a/lib/config.cc b/lib/config.cc index 6cc59869..6c94a404 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -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) { - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); 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) { - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); 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; - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); } *out = list; diff --git a/lib/database.cc b/lib/database.cc index 8f687eee..edb63dd8 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -468,7 +468,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch, error.get_msg ().c_str ()); notmuch->exception_reported = true; *message_ret = NULL; - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (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) { - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); 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 ()); - ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + ret = _notmuch_xapian_error (error); 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; - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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; - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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; - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); } 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; - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); } DONE: diff --git a/lib/directory.cc b/lib/directory.cc index 5cf64d7f..8eb3c562 100644 --- a/lib/directory.cc +++ b/lib/directory.cc @@ -206,7 +206,7 @@ _notmuch_directory_find_or_create (notmuch_database_t *notmuch, notmuch->exception_reported = true; notmuch_directory_destroy (directory); directory = NULL; - *status_ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + *status_ret = _notmuch_xapian_error (error); } 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; - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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; - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error (error); } notmuch_directory_destroy (directory); diff --git a/lib/message-property.cc b/lib/message-property.cc index 7f520340..87eaaf24 100644 --- a/lib/message-property.cc +++ b/lib/message-property.cc @@ -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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } if (! _notmuch_message_frozen (message)) diff --git a/lib/message.cc b/lib/message.cc index ea815efe..d1e91581 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -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; - *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; + *status_ret = _notmuch_xapian_error_private (error); 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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } *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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (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); - status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error_private (error); } DONE: @@ -1645,7 +1645,7 @@ _notmuch_message_has_term (notmuch_message_t *message, ! strcmp ((*i).c_str (), term)) out = true; } catch (Xapian::Error &error) { - status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; + status = _notmuch_xapian_error_private (error); } 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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } 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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } return NOTMUCH_STATUS_SUCCESS; diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 89ab5397..dd45f89d 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -746,6 +746,9 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char ** 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 @@ -767,6 +770,22 @@ _notmuch_talloc_steal (const void *new_ctx, const T *ptr) #else #define NODISCARD /**/ #endif + +/* Map a Xapian exception into a notmuch status code. */ +static inline notmuch_private_status_t +_notmuch_xapian_error_private (const Xapian::Error &error) +{ + const char *type = error.get_type (); + return (! strcmp (type, "DatabaseModifiedError")) ? + NOTMUCH_PRIVATE_STATUS_OPERATION_INVALIDATED : NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; +} + +static inline notmuch_status_t +_notmuch_xapian_error (const Xapian::Error &error) +{ + return COERCE_STATUS (_notmuch_xapian_error_private (error), + "mapping Xapian exception"); +} #endif #endif diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc index 930888e9..3f6d9ed8 100644 --- a/lib/parse-sexp.cc +++ b/lib/parse-sexp.cc @@ -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; - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } } return NOTMUCH_STATUS_SUCCESS; diff --git a/lib/query.cc b/lib/query.cc index 1761cdc9..3a957d62 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -206,7 +206,7 @@ _notmuch_query_string_to_xapian_query (notmuch_database_t *notmuch, } msg = error.get_msg (); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } return NOTMUCH_STATUS_SUCCESS; } @@ -465,7 +465,7 @@ _notmuch_query_search_documents (notmuch_query_t *query, notmuch->exception_reported = true; talloc_free (messages); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (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); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } *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 (); - return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + return _notmuch_xapian_error (error); } return NOTMUCH_STATUS_SUCCESS; -- 2.39.5 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-leave@notmuchmail.org