database error
[notmuch-archives.git] / db / 1e5181e3ea8f6edfc6b9b736e9d03a9d027fe8
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 4E7806DE1633\r
6  for <notmuch@notmuchmail.org>; Sun,  6 Sep 2015 06:58:45 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.649\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.649 tagged_above=-999 required=5 tests=[AWL=-1.041,\r
12   RCVD_IN_BRBL_LASTEXT=1.644, RCVD_IN_SBL=2.596, RP_MATCHES_RCVD=-0.55]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id 4IASAOxUZILH for <notmuch@notmuchmail.org>;\r
17  Sun,  6 Sep 2015 06:58:43 -0700 (PDT)\r
18 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 8B76E6DE1636\r
20  for <notmuch@notmuchmail.org>; Sun,  6 Sep 2015 06:58:43 -0700 (PDT)\r
21 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1ZYZnX-0002x9-2s; Sun, 06 Sep 2015 10:15:55 -0300\r
24 Received: (nullmailer pid 29728 invoked by uid 1000); Sun, 06 Sep 2015\r
25  13:15:48 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 2/3] cli/count: update to use notmuch_query_search_messages_st\r
29 Date: Sun,  6 Sep 2015 10:15:46 -0300\r
30 Message-Id: <1441545347-29549-2-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.5.1\r
32 In-Reply-To: <1441545347-29549-1-git-send-email-david@tethera.net>\r
33 References: <1441545347-29549-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.18\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sun, 06 Sep 2015 13:58:45 -0000\r
47 \r
48 This brings back status information that may have been hidden by the\r
49 great library logging conversion.\r
50 \r
51 Note the change of the internal API / return-value for count_files The\r
52 other count calls to the lib will also get error handling when that\r
53 API is updated in the lib.\r
54 ---\r
55  notmuch-count.c    | 22 ++++++++++++++++------\r
56  test/T060-count.sh | 30 ++++++++++++++++++++++++++++++\r
57  2 files changed, 46 insertions(+), 6 deletions(-)\r
58 \r
59 diff --git a/notmuch-count.c b/notmuch-count.c\r
60 index f26e726..65e1f4e 100644\r
61 --- a/notmuch-count.c\r
62 +++ b/notmuch-count.c\r
63 @@ -34,17 +34,19 @@ enum {\r
64      EXCLUDE_FALSE,\r
65  };\r
66  \r
67 -static unsigned int\r
68 +/* Return the number of files matching the query, or -1 for an error */\r
69 +static int\r
70  count_files (notmuch_query_t *query)\r
71  {\r
72      notmuch_messages_t *messages;\r
73      notmuch_message_t *message;\r
74      notmuch_filenames_t *filenames;\r
75 -    unsigned int count = 0;\r
76 +    notmuch_status_t status;\r
77 +    int count = 0;\r
78  \r
79 -    messages = notmuch_query_search_messages (query);\r
80 -    if (messages == NULL)\r
81 -       return 0;\r
82 +    status = notmuch_query_search_messages_st (query, &messages);\r
83 +    if (print_status_query ("notmuch count", query, status))\r
84 +       return -1;\r
85  \r
86      for (;\r
87          notmuch_messages_valid (messages);\r
88 @@ -72,6 +74,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
89  {\r
90      notmuch_query_t *query;\r
91      size_t i;\r
92 +    int count;\r
93      unsigned long revision;\r
94      const char *uuid;\r
95      int ret = 0;\r
96 @@ -93,7 +96,13 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
97         printf ("%u", notmuch_query_count_threads (query));\r
98         break;\r
99      case OUTPUT_FILES:\r
100 -       printf ("%u", count_files (query));\r
101 +       count = count_files (query);\r
102 +       if (count >= 0) {\r
103 +           printf ("%u", count);\r
104 +       } else {\r
105 +           ret = -1;\r
106 +           goto DONE;\r
107 +       }\r
108         break;\r
109      }\r
110  \r
111 @@ -104,6 +113,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
112         fputs ("\n", stdout);\r
113      }\r
114  \r
115 +  DONE:\r
116      notmuch_query_destroy (query);\r
117  \r
118      return ret;\r
119 diff --git a/test/T060-count.sh b/test/T060-count.sh\r
120 index 5ef3879..3fec94e 100755\r
121 --- a/test/T060-count.sh\r
122 +++ b/test/T060-count.sh\r
123 @@ -93,5 +93,35 @@ notmuch count --output=messages >>EXPECTED\r
124  notmuch count --output=messages tag:inbox >>EXPECTED\r
125  test_expect_equal_file EXPECTED OUTPUT\r
126  \r
127 +backup_database\r
128 +test_begin_subtest "error message for database open"\r
129 +dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3\r
130 +notmuch count '*' 2>OUTPUT 1>/dev/null\r
131 +output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)\r
132 +test_expect_equal "${output}" "A Xapian exception occurred opening database"\r
133 +restore_database\r
134 +\r
135 +cat <<EOF > count-files.gdb\r
136 +set breakpoint pending on\r
137 +break count_files\r
138 +commands\r
139 +shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB\r
140 +continue\r
141 +end\r
142 +run\r
143 +EOF\r
144 +\r
145 +backup_database\r
146 +test_begin_subtest "error message from query_search_messages"\r
147 +gdb --batch-silent --return-child-result -x count-files.gdb \\r
148 +    --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null\r
149 +cat <<EOF > EXPECTED\r
150 +notmuch count: A Xapian exception occurred\r
151 +A Xapian exception occurred performing query\r
152 +Query string was: *\r
153 +EOF\r
154 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean\r
155 +test_expect_equal_file EXPECTED OUTPUT.clean\r
156 +restore_database\r
157  \r
158  test_done\r
159 -- \r
160 2.5.1\r
161 \r