unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Third batch of API cleanup for exception safety
@ 2020-07-05 13:00 David Bremner
  2020-07-05 13:00 ` [PATCH 01/11] lib: add regression test for n_m_get_date; clarify API David Bremner
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch

This is a continuation of

     id:20200704151805.3717715-1-david@tethera.net

and probably needs to be applied on top.

There are two patches not fitting the pattern of "add test" or "add
try/catch to fix test".

[PATCH 02/11] lib: use LOG_XAPIAN_EXCEPTION in n_m_get_date
[PATCH 11/11] lib: use COERCE_STATUS in n_m_{add,remove}_tag

There is one subtle API change. I call this the Emergency First Aid
theory of API stability: it only changes the behaviour in cases that
where previously crashing.

[PATCH 05/11] lib: add known broken test for n_m_count_files

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/11] lib: add regression test for n_m_get_date; clarify API
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 02/11] lib: use LOG_XAPIAN_EXCEPTION in n_m_get_date David Bremner
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This function catches Xapian exceptions. The test is intended to make
sure it stays that way.
---
 lib/notmuch.h          |  2 ++
 test/T560-lib-error.sh | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index c7b21060..b7de7652 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1528,6 +1528,8 @@ notmuch_message_set_flag (notmuch_message_t *message,
  * For the original textual representation of the Date header from the
  * message call notmuch_message_get_header() with a header value of
  * "date".
+ *
+ * Returns 0 in case of error.
  */
 time_t
 notmuch_message_get_date (notmuch_message_t *message);
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 06b43ef2..ab7a24d1 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -470,5 +470,21 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Handle getting date from closed database"
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        time_t result;
+        result = notmuch_message_get_date (message);
+        printf("%d\n%d\n", message != NULL, result == 0);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/11] lib: use LOG_XAPIAN_EXCEPTION in n_m_get_date
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
  2020-07-05 13:00 ` [PATCH 01/11] lib: add regression test for n_m_get_date; clarify API David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 03/11] test: add known broken test for n_m_get_tags David Bremner
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This should not change functionality, but does slightly reduce code
duplication. Perhaps more importantly it allows consistent changes to
all of the similar exception handling in message.cc.
---
 lib/message.cc | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 81278d5e..6d78663b 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1216,9 +1216,7 @@ notmuch_message_get_date (notmuch_message_t *message)
     try {
 	value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
     } catch (Xapian::Error &error) {
-	_notmuch_database_log (notmuch_message_get_database (message), "A Xapian exception occurred when reading date: %s\n",
-			       error.get_msg ().c_str ());
-	message->notmuch->exception_reported = true;
+	LOG_XAPIAN_EXCEPTION (message, error);
 	return 0;
     }
 
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/11] test: add known broken test for n_m_get_tags
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
  2020-07-05 13:00 ` [PATCH 01/11] lib: add regression test for n_m_get_date; clarify API David Bremner
  2020-07-05 13:00 ` [PATCH 02/11] lib: use LOG_XAPIAN_EXCEPTION in n_m_get_date David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 04/11] lib: catch Xapian exceptions in n_m_get_tags David Bremner
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This will be fixed in the next commit.
---
 test/T560-lib-error.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index ab7a24d1..94a0f470 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -486,5 +486,22 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Handle getting tags from closed database"
+test_subtest_known_broken
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        notmuch_tags_t *result;
+        result = notmuch_message_get_tags (message);
+        printf("%d\n%d\n", message != NULL, result == NULL);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/11] lib: catch Xapian exceptions in n_m_get_tags
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (2 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 03/11] test: add known broken test for n_m_get_tags David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 05/11] lib: add known broken test for n_m_count_files David Bremner
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This allows the function to return an error value rather than
crashing.
---
 lib/message.cc         | 7 ++++++-
 test/T560-lib-error.sh | 1 -
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 6d78663b..9b7d4bc4 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1231,7 +1231,12 @@ notmuch_message_get_tags (notmuch_message_t *message)
 {
     notmuch_tags_t *tags;
 
-    _notmuch_message_ensure_metadata (message, message->tag_list);
+    try {
+	_notmuch_message_ensure_metadata (message, message->tag_list);
+    } catch (Xapian::Error &error) {
+	LOG_XAPIAN_EXCEPTION (message, error);
+	return NULL;
+    }
 
     tags = _notmuch_tags_create (message, message->tag_list);
     /* _notmuch_tags_create steals the reference to the tag_list, but
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 94a0f470..cda3df78 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -487,7 +487,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle getting tags from closed database"
-test_subtest_known_broken
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_tags_t *result;
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/11] lib: add known broken test for n_m_count_files
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (3 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 04/11] lib: catch Xapian exceptions in n_m_get_tags David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 06/11] lib: catch Xapian exceptions in n_m_count_files David Bremner
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This will be fixed in the next commit.
---
 test/T560-lib-error.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index cda3df78..8207727e 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -502,5 +502,22 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Handle counting files from closed database"
+test_subtest_known_broken
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        int result;
+        result = notmuch_message_count_files (message);
+        printf("%d\n%d\n", message != NULL, result < 0);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/11] lib: catch Xapian exceptions in n_m_count_files
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (4 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 05/11] lib: add known broken test for n_m_count_files David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 07/11] test: add known broken test for n_m_add_tag with closed db David Bremner
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

This will require some care for the caller to check the sign, and not
just add error returns into a running total.
---
 lib/message.cc         | 7 ++++++-
 lib/notmuch.h          | 3 ++-
 test/T560-lib-error.sh | 1 -
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 9b7d4bc4..b7d7c96b 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1156,7 +1156,12 @@ notmuch_message_get_filenames (notmuch_message_t *message)
 int
 notmuch_message_count_files (notmuch_message_t *message)
 {
-    _notmuch_message_ensure_filename_list (message);
+    try {
+	_notmuch_message_ensure_filename_list (message);
+    } catch (Xapian::Error &error) {
+	LOG_XAPIAN_EXCEPTION (message, error);
+	return -1;
+    }
 
     return _notmuch_string_list_length (message->filename_list);
 }
diff --git a/lib/notmuch.h b/lib/notmuch.h
index b7de7652..0f386397 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1412,7 +1412,8 @@ notmuch_message_get_replies (notmuch_message_t *message);
 
 /**
  * Get the total number of files associated with a message.
- * @returns Non-negative integer
+ * @returns Non-negative integer for file count.
+ * @returns Negative integer for error.
  * @since libnotmuch 5.0 (notmuch 0.25)
  */
 int
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 8207727e..507e0e07 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -503,7 +503,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle counting files from closed database"
-test_subtest_known_broken
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         int result;
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/11] test: add known broken test for n_m_add_tag with closed db
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (5 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 06/11] lib: catch Xapian exceptions in n_m_count_files David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag David Bremner
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Exception will be caught in next commit.
---
 test/T560-lib-error.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 507e0e07..f3e126e3 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -518,5 +518,21 @@ cat <<EOF > EXPECTED
 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;
+        status = notmuch_message_add_tag (message, "boom");
+        printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
 
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (6 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 07/11] test: add known broken test for n_m_add_tag with closed db David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 09/11] test: add broken test for n_m_remove_tag David Bremner
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/11] test: add broken test for n_m_remove_tag
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (7 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 10/11] lib: catch Xapian exceptions in n_m_remove_tag David Bremner
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Exception will be caught in next commit.
---
 test/T560-lib-error.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 7de13bb3..4640e2c9 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -534,4 +534,21 @@ cat <<EOF > EXPECTED
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
+test_begin_subtest "Handle removing tag with closed database"
+test_subtest_known_broken
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+    {
+        notmuch_status_t status;
+        status = notmuch_message_remove_tag (message, "boom");
+        printf("%d\n%d\n", message != NULL, status == NOTMUCH_STATUS_XAPIAN_EXCEPTION);
+    }
+EOF
+cat <<EOF > EXPECTED
+== stdout ==
+1
+1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/11] lib: catch Xapian exceptions in n_m_remove_tag
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (8 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 09/11] test: add broken test for n_m_remove_tag David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-05 13:00 ` [PATCH 11/11] lib: use COERCE_STATUS in n_m_{add,remove}_tag David Bremner
  2020-07-14 10:33 ` Third batch of API cleanup for exception safety David Bremner
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

The churn here is again mainly re-indentation.
---
 lib/message.cc         | 33 +++++++++++++++++++--------------
 test/T560-lib-error.sh |  1 -
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 7c9af079..e4463d05 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1648,24 +1648,29 @@ notmuch_message_remove_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_remove_term (message, "tag", tag);
-    if (private_status) {
-	INTERNAL_ERROR ("_notmuch_message_remove_term return unexpected value: %d\n",
-			private_status);
-    }
+	private_status = _notmuch_message_remove_term (message, "tag", tag);
+	if (private_status) {
+	    INTERNAL_ERROR ("_notmuch_message_remove_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 4640e2c9..afb53346 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -535,7 +535,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle removing 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/11] lib: use COERCE_STATUS in n_m_{add,remove}_tag
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (9 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 10/11] lib: catch Xapian exceptions in n_m_remove_tag David Bremner
@ 2020-07-05 13:00 ` David Bremner
  2020-07-14 10:33 ` Third batch of API cleanup for exception safety David Bremner
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-05 13:00 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

Currently I don't know of a good way of testing this, but at least in
principle a Xapian exception in _notmuch_message_{add,remove}_term
would cause an abort in the library.
---
 lib/message.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index e4463d05..4e1be986 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1627,8 +1627,9 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)
 
 	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);
+	    return COERCE_STATUS (private_status,
+				  "_notmuch_message_remove_term return unexpected value: %d\n",
+				  private_status);
 	}
 
 	if (! message->frozen)
@@ -1661,8 +1662,9 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)
 
 	private_status = _notmuch_message_remove_term (message, "tag", tag);
 	if (private_status) {
-	    INTERNAL_ERROR ("_notmuch_message_remove_term return unexpected value: %d\n",
-			    private_status);
+	    return COERCE_STATUS (private_status,
+				  "_notmuch_message_remove_term return unexpected value: %d\n",
+				  private_status);
 	}
 
 	if (! message->frozen)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: Third batch of API cleanup for exception safety
  2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
                   ` (10 preceding siblings ...)
  2020-07-05 13:00 ` [PATCH 11/11] lib: use COERCE_STATUS in n_m_{add,remove}_tag David Bremner
@ 2020-07-14 10:33 ` David Bremner
  11 siblings, 0 replies; 13+ messages in thread
From: David Bremner @ 2020-07-14 10:33 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> This is a continuation of
>
>      id:20200704151805.3717715-1-david@tethera.net
>
> and probably needs to be applied on top.
>
> There are two patches not fitting the pattern of "add test" or "add
> try/catch to fix test".

pushed this batch of patches to master.

d

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-07-14 10:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 13:00 Third batch of API cleanup for exception safety David Bremner
2020-07-05 13:00 ` [PATCH 01/11] lib: add regression test for n_m_get_date; clarify API David Bremner
2020-07-05 13:00 ` [PATCH 02/11] lib: use LOG_XAPIAN_EXCEPTION in n_m_get_date David Bremner
2020-07-05 13:00 ` [PATCH 03/11] test: add known broken test for n_m_get_tags David Bremner
2020-07-05 13:00 ` [PATCH 04/11] lib: catch Xapian exceptions in n_m_get_tags David Bremner
2020-07-05 13:00 ` [PATCH 05/11] lib: add known broken test for n_m_count_files David Bremner
2020-07-05 13:00 ` [PATCH 06/11] lib: catch Xapian exceptions in n_m_count_files David Bremner
2020-07-05 13:00 ` [PATCH 07/11] test: add known broken test for n_m_add_tag with closed db David Bremner
2020-07-05 13:00 ` [PATCH 08/11] lib: catch Xapian exceptions in n_m_add_tag David Bremner
2020-07-05 13:00 ` [PATCH 09/11] test: add broken test for n_m_remove_tag David Bremner
2020-07-05 13:00 ` [PATCH 10/11] lib: catch Xapian exceptions in n_m_remove_tag David Bremner
2020-07-05 13:00 ` [PATCH 11/11] lib: use COERCE_STATUS in n_m_{add,remove}_tag David Bremner
2020-07-14 10:33 ` Third batch of API cleanup for exception safety David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).