[PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag

Subject: [PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag

Date: Sun, 5 Jul 2020 10:00:23 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


This is mostly just (horizontal) code movement due to wrapping
everything in a try / catch.
---
 lib/message.cc         | 34 ++++++++++++++++++++--------------
 test/T560-lib-error.sh |  1 -
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index b7d7c96b..7c9af079 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1614,24 +1614,30 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)
     notmuch_private_status_t private_status;
     notmuch_status_t status;
 
-    status = _notmuch_database_ensure_writable (message->notmuch);
-    if (status)
-	return status;
+    try {
+	status = _notmuch_database_ensure_writable (message->notmuch);
+	if (status)
+	    return status;
 
-    if (tag == NULL)
-	return NOTMUCH_STATUS_NULL_POINTER;
+	if (tag == NULL)
+	    return NOTMUCH_STATUS_NULL_POINTER;
 
-    if (strlen (tag) > NOTMUCH_TAG_MAX)
-	return NOTMUCH_STATUS_TAG_TOO_LONG;
+	if (strlen (tag) > NOTMUCH_TAG_MAX)
+	    return NOTMUCH_STATUS_TAG_TOO_LONG;
 
-    private_status = _notmuch_message_add_term (message, "tag", tag);
-    if (private_status) {
-	INTERNAL_ERROR ("_notmuch_message_add_term return unexpected value: %d\n",
-			private_status);
-    }
+	private_status = _notmuch_message_add_term (message, "tag", tag);
+	if (private_status) {
+	    INTERNAL_ERROR ("_notmuch_message_add_term return unexpected value: %d\n",
+			    private_status);
+	}
 
-    if (! message->frozen)
-	_notmuch_message_sync (message);
+	if (! message->frozen)
+	    _notmuch_message_sync (message);
+
+    } catch (Xapian::Error &error) {
+	LOG_XAPIAN_EXCEPTION (message, error);
+	return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+    }
 
     return NOTMUCH_STATUS_SUCCESS;
 }
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index f3e126e3..7de13bb3 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -519,7 +519,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle adding tag with closed database"
-test_subtest_known_broken
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_status_t status;
-- 
2.27.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: