--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 C9E5C6DE15C9\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Jun 2015 08:04:26 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.223\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.223 tagged_above=-999 required=5 tests=[AWL=0.213, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] 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 dI5h3XPQr1ie for <notmuch@notmuchmail.org>;\r
+ Sun, 7 Jun 2015 08:04:25 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 1B0096DE1557\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Jun 2015 08:04:25 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1Z1c6x-0004oy-EG; Sun, 07 Jun 2015 15:03:43 +0000\r
+Received: (nullmailer pid 7866 invoked by uid 1000); Sun, 07 Jun 2015\r
+ 15:02:11 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 09/10] cli/count: update to use\r
+ notmuch_query_search_messages_st\r
+Date: Sun, 7 Jun 2015 17:02:02 +0200\r
+Message-Id: <1433689323-7520-10-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1433689323-7520-1-git-send-email-david@tethera.net>\r
+References: <1433689323-7520-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, 07 Jun 2015 15:04:26 -0000\r
+\r
+This brings back status information that may have been hidden by the\r
+great library logging conversion.\r
+---\r
+ notmuch-count.c | 16 ++++++++++------\r
+ test/T060-count.sh | 30 ++++++++++++++++++++++++++++++\r
+ 2 files changed, 40 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index 57a88a8..25b05df 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -33,17 +33,18 @@ enum {\r
+ EXCLUDE_FALSE,\r
+ };\r
+ \r
+-static unsigned int\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
+@@ -71,6 +72,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
+ \r
+ query = notmuch_query_create (notmuch, query_str);\r
+ if (query == NULL) {\r
+@@ -89,7 +91,9 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+ printf ("%u\n", notmuch_query_count_threads (query));\r
+ break;\r
+ case OUTPUT_FILES:\r
+- printf ("%u\n", count_files (query));\r
++ count = count_files (query);\r
++ if (count >= 0)\r
++ printf ("%u\n", count);\r
+ break;\r
+ }\r
+ \r
+diff --git a/test/T060-count.sh b/test/T060-count.sh\r
+index da86c8c..973a42d 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.1.4\r
+\r