--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 4E7806DE1633\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:45 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.649\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.649 tagged_above=-999 required=5 tests=[AWL=-1.041,\r
+ RCVD_IN_BRBL_LASTEXT=1.644, RCVD_IN_SBL=2.596, RP_MATCHES_RCVD=-0.55]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4IASAOxUZILH for <notmuch@notmuchmail.org>;\r
+ Sun, 6 Sep 2015 06:58:43 -0700 (PDT)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 8B76E6DE1636\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:43 -0700 (PDT)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1ZYZnX-0002x9-2s; Sun, 06 Sep 2015 10:15:55 -0300\r
+Received: (nullmailer pid 29728 invoked by uid 1000); Sun, 06 Sep 2015\r
+ 13:15:48 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] cli/count: update to use notmuch_query_search_messages_st\r
+Date: Sun, 6 Sep 2015 10:15:46 -0300\r
+Message-Id: <1441545347-29549-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.1\r
+In-Reply-To: <1441545347-29549-1-git-send-email-david@tethera.net>\r
+References: <1441545347-29549-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 06 Sep 2015 13:58:45 -0000\r
+\r
+This brings back status information that may have been hidden by the\r
+great library logging conversion.\r
+\r
+Note the change of the internal API / return-value for count_files The\r
+other count calls to the lib will also get error handling when that\r
+API is updated in the lib.\r
+---\r
+ notmuch-count.c | 22 ++++++++++++++++------\r
+ test/T060-count.sh | 30 ++++++++++++++++++++++++++++++\r
+ 2 files changed, 46 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index f26e726..65e1f4e 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -34,17 +34,19 @@ enum {\r
+ EXCLUDE_FALSE,\r
+ };\r
+ \r
+-static unsigned int\r
++/* Return the number of files matching the query, or -1 for an error */\r
++static int\r
+ count_files (notmuch_query_t *query)\r
+ {\r
+ notmuch_messages_t *messages;\r
+ notmuch_message_t *message;\r
+ notmuch_filenames_t *filenames;\r
+- unsigned int count = 0;\r
++ notmuch_status_t status;\r
++ int count = 0;\r
+ \r
+- messages = notmuch_query_search_messages (query);\r
+- if (messages == NULL)\r
+- return 0;\r
++ status = notmuch_query_search_messages_st (query, &messages);\r
++ if (print_status_query ("notmuch count", query, status))\r
++ return -1;\r
+ \r
+ for (;\r
+ notmuch_messages_valid (messages);\r
+@@ -72,6 +74,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ {\r
+ notmuch_query_t *query;\r
+ size_t i;\r
++ int count;\r
+ unsigned long revision;\r
+ const char *uuid;\r
+ int ret = 0;\r
+@@ -93,7 +96,13 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ printf ("%u", notmuch_query_count_threads (query));\r
+ break;\r
+ case OUTPUT_FILES:\r
+- printf ("%u", count_files (query));\r
++ count = count_files (query);\r
++ if (count >= 0) {\r
++ printf ("%u", count);\r
++ } else {\r
++ ret = -1;\r
++ goto DONE;\r
++ }\r
+ break;\r
+ }\r
+ \r
+@@ -104,6 +113,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ fputs ("\n", stdout);\r
+ }\r
+ \r
++ DONE:\r
+ notmuch_query_destroy (query);\r
+ \r
+ return ret;\r
+diff --git a/test/T060-count.sh b/test/T060-count.sh\r
+index 5ef3879..3fec94e 100755\r
+--- a/test/T060-count.sh\r
++++ b/test/T060-count.sh\r
+@@ -93,5 +93,35 @@ notmuch count --output=messages >>EXPECTED\r
+ notmuch count --output=messages tag:inbox >>EXPECTED\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
++backup_database\r
++test_begin_subtest "error message for database open"\r
++dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3\r
++notmuch count '*' 2>OUTPUT 1>/dev/null\r
++output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)\r
++test_expect_equal "${output}" "A Xapian exception occurred opening database"\r
++restore_database\r
++\r
++cat <<EOF > count-files.gdb\r
++set breakpoint pending on\r
++break count_files\r
++commands\r
++shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB\r
++continue\r
++end\r
++run\r
++EOF\r
++\r
++backup_database\r
++test_begin_subtest "error message from query_search_messages"\r
++gdb --batch-silent --return-child-result -x count-files.gdb \\r
++ --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null\r
++cat <<EOF > EXPECTED\r
++notmuch count: A Xapian exception occurred\r
++A Xapian exception occurred performing query\r
++Query string was: *\r
++EOF\r
++sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
++test_expect_equal_file EXPECTED OUTPUT.clean\r
++restore_database\r
+ \r
+ test_done\r
+-- \r
+2.5.1\r
+\r