Re: notmuch and "mute" -- useful to anyone?
[notmuch-archives.git] / d4 / b50261fe8f8ba1d4f6958b0aa4952eb9454f37
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 olra.theworths.org (Postfix) with ESMTP id F2799431FD2\r
6         for <notmuch@notmuchmail.org>; Sat, 14 Mar 2015 10:03:54 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.438\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
12         tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id HhaMBV6kHOw3 for <notmuch@notmuchmail.org>;\r
16         Sat, 14 Mar 2015 10:03:51 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18         [87.98.215.224])\r
19         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 5B3A7431FCB\r
22         for <notmuch@notmuchmail.org>; Sat, 14 Mar 2015 10:03:51 -0700 (PDT)\r
23 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
24         4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
25         id 1YWpSu-00026O-EC; Sat, 14 Mar 2015 17:03:08 +0000\r
26 Received: (nullmailer pid 4995 invoked by uid 1000); Sat, 14 Mar 2015\r
27         17:02:41 -0000\r
28 From: David Bremner <david@tethera.net>\r
29 To: notmuch@notmuchmail.org\r
30 Subject: [Patch v4 8/9] lib: replace almost all fprintfs in library with\r
31         _n_d_log\r
32 Date: Sat, 14 Mar 2015 18:02:33 +0100\r
33 Message-Id: <1426352554-4383-9-git-send-email-david@tethera.net>\r
34 X-Mailer: git-send-email 2.1.4\r
35 In-Reply-To: <1426352554-4383-1-git-send-email-david@tethera.net>\r
36 References: <1426352554-4383-1-git-send-email-david@tethera.net>\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sat, 14 Mar 2015 17:03:55 -0000\r
50 \r
51 This is not supposed to change any functionality from an end user\r
52 point of view. Note that it will eliminate some output to stderr. The\r
53 query debugging output is left as is; it doesn't really fit with the\r
54 current primitive logging model. The remaining "bad" fprintf will need\r
55 an internal API change.\r
56 ---\r
57  lib/database.cc        | 38 +++++++++++++++++++++-----------------\r
58  lib/directory.cc       |  4 ++--\r
59  lib/index.cc           | 11 +++++++----\r
60  lib/message.cc         |  6 +++---\r
61  lib/query.cc           |  8 ++++----\r
62  test/T560-lib-error.sh |  6 +++++-\r
63  6 files changed, 42 insertions(+), 31 deletions(-)\r
64 \r
65 diff --git a/lib/database.cc b/lib/database.cc\r
66 index 0409128..6828654 100644\r
67 --- a/lib/database.cc\r
68 +++ b/lib/database.cc\r
69 @@ -499,7 +499,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,\r
70  \r
71         return NOTMUCH_STATUS_SUCCESS;\r
72      } catch (const Xapian::Error &error) {\r
73 -       fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",\r
74 +       _notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n",\r
75                  error.get_msg().c_str());\r
76         notmuch->exception_reported = TRUE;\r
77         *message_ret = NULL;\r
78 @@ -732,7 +732,7 @@ notmuch_status_t\r
79  _notmuch_database_ensure_writable (notmuch_database_t *notmuch)\r
80  {\r
81      if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {\r
82 -       fprintf (stderr, "Cannot write to a read-only database.\n");\r
83 +       _notmuch_database_log (notmuch, "Cannot write to a read-only database.\n");\r
84         return NOTMUCH_STATUS_READ_ONLY_DATABASE;\r
85      }\r
86  \r
87 @@ -1025,7 +1025,7 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
88         } catch (const Xapian::Error &error) {\r
89             status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
90             if (! notmuch->exception_reported) {\r
91 -               fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",\r
92 +               _notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n",\r
93                          error.get_msg().c_str());\r
94             }\r
95         }\r
96 @@ -1157,12 +1157,12 @@ notmuch_database_compact (const char *path,\r
97      }\r
98  \r
99      if (stat (backup_path, &statbuf) != -1) {\r
100 -       fprintf (stderr, "Path already exists: %s\n", backup_path);\r
101 +       _notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path);\r
102         ret = NOTMUCH_STATUS_FILE_ERROR;\r
103         goto DONE;\r
104      }\r
105      if (errno != ENOENT) {\r
106 -       fprintf (stderr, "Unknown error while stat()ing path: %s\n",\r
107 +       _notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n",\r
108                  strerror (errno));\r
109         ret = NOTMUCH_STATUS_FILE_ERROR;\r
110         goto DONE;\r
111 @@ -1182,20 +1182,20 @@ notmuch_database_compact (const char *path,\r
112         compactor.set_destdir (compact_xapian_path);\r
113         compactor.compact ();\r
114      } catch (const Xapian::Error &error) {\r
115 -       fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str());\r
116 +       _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str());\r
117         ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
118         goto DONE;\r
119      }\r
120  \r
121      if (rename (xapian_path, backup_path)) {\r
122 -       fprintf (stderr, "Error moving %s to %s: %s\n",\r
123 +       _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",\r
124                  xapian_path, backup_path, strerror (errno));\r
125         ret = NOTMUCH_STATUS_FILE_ERROR;\r
126         goto DONE;\r
127      }\r
128  \r
129      if (rename (compact_xapian_path, xapian_path)) {\r
130 -       fprintf (stderr, "Error moving %s to %s: %s\n",\r
131 +       _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",\r
132                  compact_xapian_path, xapian_path, strerror (errno));\r
133         ret = NOTMUCH_STATUS_FILE_ERROR;\r
134         goto DONE;\r
135 @@ -1203,7 +1203,7 @@ notmuch_database_compact (const char *path,\r
136  \r
137      if (! keep_backup) {\r
138         if (rmtree (backup_path)) {\r
139 -           fprintf (stderr, "Error removing old database %s: %s\n",\r
140 +           _notmuch_database_log (notmuch, "Error removing old database %s: %s\n",\r
141                      backup_path, strerror (errno));\r
142             ret = NOTMUCH_STATUS_FILE_ERROR;\r
143             goto DONE;\r
144 @@ -1214,6 +1214,10 @@ notmuch_database_compact (const char *path,\r
145      if (notmuch) {\r
146         notmuch_status_t ret2;\r
147  \r
148 +       const char *str = notmuch_database_status_string (notmuch);\r
149 +       if (status_cb && str)\r
150 +           status_cb (str, closure);\r
151 +\r
152         ret2 = notmuch_database_destroy (notmuch);\r
153  \r
154         /* don't clobber previous error status */\r
155 @@ -1232,7 +1236,7 @@ notmuch_database_compact (unused (const char *path),\r
156                           unused (notmuch_compact_status_cb_t status_cb),\r
157                           unused (void *closure))\r
158  {\r
159 -    fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");\r
160 +    _notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n");\r
161      return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
162  }\r
163  #endif\r
164 @@ -1510,7 +1514,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
165             }\r
166  \r
167             if (private_status) {\r
168 -               fprintf (stderr,\r
169 +               _notmuch_database_log (notmuch,\r
170                          "Upgrade failed while creating ghost messages.\n");\r
171                 status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");\r
172                 goto DONE;\r
173 @@ -1560,7 +1564,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)\r
174      try {\r
175         (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);\r
176      } catch (const Xapian::Error &error) {\r
177 -       fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",\r
178 +       _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",\r
179                  error.get_msg().c_str());\r
180         notmuch->exception_reported = TRUE;\r
181         return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
182 @@ -1594,7 +1598,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)\r
183         if (thresh && atoi (thresh) == 1)\r
184             db->flush ();\r
185      } catch (const Xapian::Error &error) {\r
186 -       fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",\r
187 +       _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",\r
188                  error.get_msg().c_str());\r
189         notmuch->exception_reported = TRUE;\r
190         return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
191 @@ -1840,7 +1844,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,\r
192         *directory = _notmuch_directory_create (notmuch, path,\r
193                                                 NOTMUCH_FIND_LOOKUP, &status);\r
194      } catch (const Xapian::Error &error) {\r
195 -       fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",\r
196 +       _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",\r
197                  error.get_msg().c_str());\r
198         notmuch->exception_reported = TRUE;\r
199         status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
200 @@ -2422,7 +2426,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
201  \r
202         _notmuch_message_sync (message);\r
203      } catch (const Xapian::Error &error) {\r
204 -       fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",\r
205 +       _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",\r
206                  error.get_msg().c_str());\r
207         notmuch->exception_reported = TRUE;\r
208         ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
209 @@ -2514,7 +2518,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,\r
210                 status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
211         }\r
212      } catch (const Xapian::Error &error) {\r
213 -       fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",\r
214 +       _notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n",\r
215                  error.get_msg().c_str());\r
216         notmuch->exception_reported = TRUE;\r
217         status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
218 @@ -2567,7 +2571,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)\r
219         _notmuch_string_list_sort (tags);\r
220         return _notmuch_tags_create (db, tags);\r
221      } catch (const Xapian::Error &error) {\r
222 -       fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",\r
223 +       _notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n",\r
224                  error.get_msg().c_str());\r
225         db->exception_reported = TRUE;\r
226         return NULL;\r
227 diff --git a/lib/directory.cc b/lib/directory.cc\r
228 index 8daaec8..b836ea2 100644\r
229 --- a/lib/directory.cc\r
230 +++ b/lib/directory.cc\r
231 @@ -186,7 +186,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch,\r
232         directory->mtime = Xapian::sortable_unserialise (\r
233             directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));\r
234      } catch (const Xapian::Error &error) {\r
235 -       fprintf (stderr,\r
236 +       _notmuch_database_log (notmuch,\r
237                  "A Xapian exception occurred creating a directory: %s.\n",\r
238                  error.get_msg().c_str());\r
239         notmuch->exception_reported = TRUE;\r
240 @@ -228,7 +228,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,\r
241  \r
242         db->replace_document (directory->document_id, directory->doc);\r
243      } catch (const Xapian::Error &error) {\r
244 -       fprintf (stderr,\r
245 +       _notmuch_database_log (notmuch,\r
246                  "A Xapian exception occurred setting directory mtime: %s.\n",\r
247                  error.get_msg().c_str());\r
248         notmuch->exception_reported = TRUE;\r
249 diff --git a/lib/index.cc b/lib/index.cc\r
250 index c88ed8d..e81aa81 100644\r
251 --- a/lib/index.cc\r
252 +++ b/lib/index.cc\r
253 @@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message,\r
254      const char *charset;\r
255  \r
256      if (! part) {\r
257 -       fprintf (stderr, "Warning: Not indexing empty mime part.\n");\r
258 +       _notmuch_database_log (_notmuch_message_database (message),\r
259 +                             "Warning: Not indexing empty mime part.\n");\r
260         return;\r
261      }\r
262  \r
263 @@ -344,7 +345,8 @@ _index_mime_part (notmuch_message_t *message,\r
264                 if (i == 1)\r
265                     continue;\r
266                 if (i > 1)\r
267 -                   fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");\r
268 +                   _notmuch_database_log (_notmuch_message_database (message),\r
269 +                                         "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");\r
270             }\r
271             if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {\r
272                 /* Don't index encrypted parts. */\r
273 @@ -367,8 +369,9 @@ _index_mime_part (notmuch_message_t *message,\r
274      }\r
275  \r
276      if (! (GMIME_IS_PART (part))) {\r
277 -       fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",\r
278 -                g_type_name (G_OBJECT_TYPE (part)));\r
279 +       _notmuch_database_log (_notmuch_message_database (message),\r
280 +                             "Warning: Not indexing unknown mime part: %s.\n",\r
281 +                             g_type_name (G_OBJECT_TYPE (part)));\r
282         return;\r
283      }\r
284  \r
285 diff --git a/lib/message.cc b/lib/message.cc\r
286 index b84e5e1..a8ca988 100644\r
287 --- a/lib/message.cc\r
288 +++ b/lib/message.cc\r
289 @@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,\r
290  \r
291         doc_id = _notmuch_database_generate_doc_id (notmuch);\r
292      } catch (const Xapian::Error &error) {\r
293 -       fprintf (stderr, "A Xapian exception occurred creating message: %s\n",\r
294 +       _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",\r
295                  error.get_msg().c_str());\r
296         notmuch->exception_reported = TRUE;\r
297         *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;\r
298 @@ -467,7 +467,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)\r
299                 return talloc_strdup (message, value.c_str ());\r
300  \r
301         } catch (Xapian::Error &error) {\r
302 -           fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",\r
303 +           _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",\r
304                      error.get_msg().c_str());\r
305             message->notmuch->exception_reported = TRUE;\r
306             return NULL;\r
307 @@ -921,7 +921,7 @@ notmuch_message_get_date (notmuch_message_t *message)\r
308      try {\r
309         value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);\r
310      } catch (Xapian::Error &error) {\r
311 -       fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",\r
312 +       _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",\r
313                  error.get_msg().c_str());\r
314         message->notmuch->exception_reported = TRUE;\r
315         return 0;\r
316 diff --git a/lib/query.cc b/lib/query.cc\r
317 index 57aa6d2..7b59786 100644\r
318 --- a/lib/query.cc\r
319 +++ b/lib/query.cc\r
320 @@ -296,9 +296,9 @@ notmuch_query_search_messages_st (notmuch_query_t *query,\r
321         return NOTMUCH_STATUS_SUCCESS;\r
322  \r
323      } catch (const Xapian::Error &error) {\r
324 -       fprintf (stderr, "A Xapian exception occurred performing query: %s\n",\r
325 +       _notmuch_database_log (notmuch, "A Xapian exception occurred performing query: %s\n",\r
326                  error.get_msg().c_str());\r
327 -       fprintf (stderr, "Query string was: %s\n", query->query_string);\r
328 +       _notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);\r
329         notmuch->exception_reported = TRUE;\r
330         talloc_free (messages);\r
331         return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
332 @@ -597,9 +597,9 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
333         count = mset.get_matches_estimated();\r
334  \r
335      } catch (const Xapian::Error &error) {\r
336 -       fprintf (stderr, "A Xapian exception occurred: %s\n",\r
337 +       _notmuch_database_log (notmuch, "A Xapian exception occurred: %s\n",\r
338                  error.get_msg().c_str());\r
339 -       fprintf (stderr, "Query string was: %s\n", query->query_string);\r
340 +       _notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);\r
341      }\r
342  \r
343      return count;\r
344 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh\r
345 index dc2022f..7621e7f 100755\r
346 --- a/test/T560-lib-error.sh\r
347 +++ b/test/T560-lib-error.sh\r
348 @@ -56,6 +56,9 @@ int main (int argc, char** argv)\r
349       fprintf (stderr, "error opening database: %d\n", stat);\r
350     }\r
351     stat = notmuch_database_add_message (db, "/dev/null", NULL);\r
352 +   if (stat)\r
353 +       fputs (notmuch_database_status_string (db), stderr);\r
354 +\r
355  }\r
356  EOF\r
357  cat <<EOF >EXPECTED\r
358 @@ -83,8 +86,9 @@ int main (int argc, char** argv)\r
359  EOF\r
360  cat <<EOF >EXPECTED\r
361  == stdout ==\r
362 -== stderr ==\r
363  Path already exists: CWD/mail\r
364 +\r
365 +== stderr ==\r
366  EOF\r
367  test_expect_equal_file EXPECTED OUTPUT\r
368  \r
369 -- \r
370 2.1.4\r
371 \r