From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 11/11] lib: catch exceptions in n_m_get_flag, provide n_m_get_flag_st
Date: Sat, 4 Jul 2020 12:18:05 -0300 [thread overview]
Message-ID: <20200704151805.3717715-12-david@tethera.net> (raw)
In-Reply-To: <20200704151805.3717715-1-david@tethera.net>
It's not very nice to return FALSE for an error, so provide
notmuch_message_get_flag_st as a migration path.
---
lib/message.cc | 33 +++++++++++++++++++++++++++++----
lib/notmuch.h | 25 +++++++++++++++++++++++++
test/T560-lib-error.sh | 18 +++++++++++++++++-
3 files changed, 71 insertions(+), 5 deletions(-)
diff --git a/lib/message.cc b/lib/message.cc
index 8e43a393..81278d5e 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1161,15 +1161,40 @@ notmuch_message_count_files (notmuch_message_t *message)
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)
{
- 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
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e544aafd..c7b21060 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1485,11 +1485,36 @@ typedef enum _notmuch_message_flag {
/**
* Get a value of a flag for the email corresponding to 'message'.
+ *
+ * returns FALSE in case of errors.
+ *
+ * @deprecated Deprecated as of libnotmuch 5.2 (notmuch 0.31). Please
+ * use notmuch_message_get_flag_st instead.
*/
+NOTMUCH_DEPRECATED(5,2)
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.2 (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'.
*/
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 68aadcdb..06b43ef2 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -438,7 +438,6 @@ EOF
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;
@@ -454,5 +453,22 @@ cat <<EOF > EXPECTED
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "Handle getting ghost flag from closed database (new API)"
+cat c_head2 - c_tail <<'EOF' | test_C ${MAIL_DIR}
+ {
+ notmuch_bool_t result;
+ notmuch_status_t status;
+ status = notmuch_message_get_flag_st (message, NOTMUCH_MESSAGE_FLAG_GHOST, &result);
+ 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
next prev parent reply other threads:[~2020-07-04 15:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-04 15:17 Second batch of API cleanup for exception safety David Bremner
2020-07-04 15:17 ` [PATCH 01/11] test: remove unused backup_database calls David Bremner
2020-07-04 15:17 ` [PATCH 02/11] test: drop use of assert in closed db tests David Bremner
2020-07-04 15:17 ` [PATCH 03/11] lib/message: use LOG_XAPIAN_EXCEPTION in n_m_get_header David Bremner
2020-07-04 15:17 ` [PATCH 04/11] test: add regression test for n_m_get_header David Bremner
2020-07-04 15:17 ` [PATCH 05/11] lib/n_m_get_replies: doc return, initial regression test David Bremner
2020-07-04 15:18 ` [PATCH 06/11] lib: add known broken test for notmuch_message_get_filename David Bremner
2020-07-04 15:18 ` [PATCH 07/11] lib/n_m_g_filename: catch Xapian exceptions, document NULL return David Bremner
2020-07-04 15:18 ` [PATCH 08/11] test: add known broken test for n_m_get_filenames David Bremner
2020-07-04 15:18 ` [PATCH 09/11] lib: catch exceptions in n_m_get_filenames David Bremner
2020-07-04 15:18 ` [PATCH 10/11] test: add known broken for n_m_get_flag on closed db David Bremner
2020-07-13 10:37 ` David Bremner
2020-07-04 15:18 ` David Bremner [this message]
2020-07-18 14:32 ` [PATCH 11/11] lib: catch exceptions in n_m_get_flag, provide n_m_get_flag_st David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200704151805.3717715-12-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).