]> git.notmuchmail.org Git - notmuch/commitdiff
lib: catch exceptions in n_m_get_flag, provide n_m_get_flag_st
authorDavid Bremner <david@tethera.net>
Sat, 4 Jul 2020 15:18:05 +0000 (12:18 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 18 Jul 2020 12:52:27 +0000 (09:52 -0300)
It's not very nice to return FALSE for an error, so provide
notmuch_message_get_flag_st as a migration path.

Bump LIBNOTMUCH_MINOR_VERSION because the API is extended.

lib/message.cc
lib/notmuch.h
test/T560-lib-error.sh

index 5ea5aa22214c7900d105b9fca1ea47d5550b91e3..4e1be986abc326842314b9d92c8553bb1aea016d 100644 (file)
@@ -1166,15 +1166,40 @@ notmuch_message_count_files (notmuch_message_t *message)
     return _notmuch_string_list_length (message->filename_list);
 }
 
     return _notmuch_string_list_length (message->filename_list);
 }
 
+notmuch_status_t
+notmuch_message_get_flag_st (notmuch_message_t *message,
+                            notmuch_message_flag_t flag,
+                            notmuch_bool_t *is_set)
+{
+    if (! is_set)
+       return NOTMUCH_STATUS_NULL_POINTER;
+
+    try {
+       if (flag == NOTMUCH_MESSAGE_FLAG_GHOST &&
+           ! NOTMUCH_TEST_BIT (message->lazy_flags, flag))
+           _notmuch_message_ensure_metadata (message, NULL);
+    } catch (Xapian::Error &error) {
+       LOG_XAPIAN_EXCEPTION (message, error);
+       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+    }
+
+    *is_set = NOTMUCH_TEST_BIT (message->flags, flag);
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
 notmuch_bool_t
 notmuch_message_get_flag (notmuch_message_t *message,
                          notmuch_message_flag_t flag)
 {
 notmuch_bool_t
 notmuch_message_get_flag (notmuch_message_t *message,
                          notmuch_message_flag_t flag)
 {
-    if (flag == NOTMUCH_MESSAGE_FLAG_GHOST &&
-       ! NOTMUCH_TEST_BIT (message->lazy_flags, flag))
-       _notmuch_message_ensure_metadata (message, NULL);
+    notmuch_bool_t is_set;
+    notmuch_status_t status;
+
+    status = notmuch_message_get_flag_st (message, flag, &is_set);
 
 
-    return NOTMUCH_TEST_BIT (message->flags, flag);
+    if (status)
+       return FALSE;
+    else
+       return is_set;
 }
 
 void
 }
 
 void
index 693e507602942ce88dde01b5ba598552e193ec24..0491e8f8df18e9cb4fef9de713d7889b71da9689 100644 (file)
@@ -58,7 +58,7 @@ NOTMUCH_BEGIN_DECLS
  * version in Makefile.local.
  */
 #define LIBNOTMUCH_MAJOR_VERSION        5
  * version in Makefile.local.
  */
 #define LIBNOTMUCH_MAJOR_VERSION        5
-#define LIBNOTMUCH_MINOR_VERSION        2
+#define LIBNOTMUCH_MINOR_VERSION        3
 #define LIBNOTMUCH_MICRO_VERSION        0
 
 
 #define LIBNOTMUCH_MICRO_VERSION        0
 
 
@@ -1486,11 +1486,36 @@ typedef enum _notmuch_message_flag {
 
 /**
  * Get a value of a flag for the email corresponding to 'message'.
 
 /**
  * Get a value of a flag for the email corresponding to 'message'.
+ *
+ * returns FALSE in case of errors.
+ *
+ * @deprecated Deprecated as of libnotmuch 5.3 (notmuch 0.31). Please
+ * use notmuch_message_get_flag_st instead.
  */
  */
+NOTMUCH_DEPRECATED(5,3)
 notmuch_bool_t
 notmuch_message_get_flag (notmuch_message_t *message,
                          notmuch_message_flag_t flag);
 
 notmuch_bool_t
 notmuch_message_get_flag (notmuch_message_t *message,
                          notmuch_message_flag_t flag);
 
+/**
+ * Get a value of a flag for the email corresponding to 'message'.
+ *
+ * @param message a message object
+ * @param flag flag to check
+ * @param is_set pointer to boolean to store flag value.
+ *
+ * @retval #NOTMUCH_STATUS_SUCCESS
+ * @retval #NOTMUCH_STATUS_NULL_POINTER is_set is NULL
+ * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION Accessing the database
+ * triggered an exception.
+ *
+ * @since libnotmuch 5.3 (notmuch 0.31)
+ */
+notmuch_status_t
+notmuch_message_get_flag_st (notmuch_message_t *message,
+                            notmuch_message_flag_t flag,
+                            notmuch_bool_t *is_set);
+
 /**
  * Set a value of a flag for the email corresponding to 'message'.
  */
 /**
  * Set a value of a flag for the email corresponding to 'message'.
  */
index ebace888681c3d807517e647ec8b5f7384c000e9..36c4c1cec9c81368d945f09af35b854a2e8a2ba1 100755 (executable)
@@ -438,7 +438,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle getting ghost flag from closed database"
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "Handle getting ghost flag from closed database"
-test_subtest_known_broken
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_bool_t result;
 cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
     {
         notmuch_bool_t result;