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 4284A429E2E
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:22:04 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 j-s4N5gE33Pd for <notmuch@notmuchmail.org>;
\r
16 Tue, 24 Mar 2015 06:22:01 -0700 (PDT)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\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 70F9B429E3B
\r
22 for <notmuch@notmuchmail.org>; Tue, 24 Mar 2015 06:22:00 -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 1YaOlj-0000qK-5L; Tue, 24 Mar 2015 13:21:19 +0000
\r
26 Received: (nullmailer pid 32640 invoked by uid 1000); Tue, 24 Mar 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
\r
30 Subject: [Patch v5 7/8] lib: replace almost all fprintfs in library with
\r
32 Date: Tue, 24 Mar 2015 09:19:45 -0400
\r
33 Message-Id: <1427203186-32194-7-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 2.1.4
\r
35 In-Reply-To: <1427203186-32194-1-git-send-email-david@tethera.net>
\r
36 References: <1426352554-4383-10-git-send-email-david@tethera.net>
\r
37 <1427203186-32194-1-git-send-email-david@tethera.net>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Tue, 24 Mar 2015 13:22:04 -0000
\r
52 This is not supposed to change any functionality from an end user
\r
53 point of view. Note that it will eliminate some output to stderr. The
\r
54 query debugging output is left as is; it doesn't really fit with the
\r
55 current primitive logging model. The remaining "bad" fprintf will need
\r
56 an internal API change.
\r
58 lib/database.cc | 38 +++++++++++++++++++++-----------------
\r
59 lib/directory.cc | 4 ++--
\r
60 lib/index.cc | 11 +++++++----
\r
61 lib/message.cc | 6 +++---
\r
62 lib/query.cc | 18 ++++++++++++------
\r
63 test/T560-lib-error.sh | 6 +++++-
\r
64 6 files changed, 50 insertions(+), 33 deletions(-)
\r
66 diff --git a/lib/database.cc b/lib/database.cc
\r
67 index 673561b..155b5aa 100644
\r
68 --- a/lib/database.cc
\r
69 +++ b/lib/database.cc
\r
70 @@ -473,7 +473,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
\r
72 return NOTMUCH_STATUS_SUCCESS;
\r
73 } catch (const Xapian::Error &error) {
\r
74 - fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
\r
75 + _notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n",
\r
76 error.get_msg().c_str());
\r
77 notmuch->exception_reported = TRUE;
\r
78 *message_ret = NULL;
\r
79 @@ -707,7 +707,7 @@ notmuch_status_t
\r
80 _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\r
82 if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
\r
83 - fprintf (stderr, "Cannot write to a read-only database.\n");
\r
84 + _notmuch_database_log (notmuch, "Cannot write to a read-only database.\n");
\r
85 return NOTMUCH_STATUS_READ_ONLY_DATABASE;
\r
88 @@ -1000,7 +1000,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
89 } catch (const Xapian::Error &error) {
\r
90 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
91 if (! notmuch->exception_reported) {
\r
92 - fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",
\r
93 + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n",
\r
94 error.get_msg().c_str());
\r
97 @@ -1132,12 +1132,12 @@ notmuch_database_compact (const char *path,
\r
100 if (stat (backup_path, &statbuf) != -1) {
\r
101 - fprintf (stderr, "Path already exists: %s\n", backup_path);
\r
102 + _notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path);
\r
103 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
106 if (errno != ENOENT) {
\r
107 - fprintf (stderr, "Unknown error while stat()ing path: %s\n",
\r
108 + _notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n",
\r
110 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
112 @@ -1157,20 +1157,20 @@ notmuch_database_compact (const char *path,
\r
113 compactor.set_destdir (compact_xapian_path);
\r
114 compactor.compact ();
\r
115 } catch (const Xapian::Error &error) {
\r
116 - fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str());
\r
117 + _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str());
\r
118 ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
122 if (rename (xapian_path, backup_path)) {
\r
123 - fprintf (stderr, "Error moving %s to %s: %s\n",
\r
124 + _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
\r
125 xapian_path, backup_path, strerror (errno));
\r
126 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
130 if (rename (compact_xapian_path, xapian_path)) {
\r
131 - fprintf (stderr, "Error moving %s to %s: %s\n",
\r
132 + _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
\r
133 compact_xapian_path, xapian_path, strerror (errno));
\r
134 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
136 @@ -1178,7 +1178,7 @@ notmuch_database_compact (const char *path,
\r
138 if (! keep_backup) {
\r
139 if (rmtree (backup_path)) {
\r
140 - fprintf (stderr, "Error removing old database %s: %s\n",
\r
141 + _notmuch_database_log (notmuch, "Error removing old database %s: %s\n",
\r
142 backup_path, strerror (errno));
\r
143 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
145 @@ -1189,6 +1189,10 @@ notmuch_database_compact (const char *path,
\r
147 notmuch_status_t ret2;
\r
149 + const char *str = notmuch_database_status_string (notmuch);
\r
150 + if (status_cb && str)
\r
151 + status_cb (str, closure);
\r
153 ret2 = notmuch_database_destroy (notmuch);
\r
155 /* don't clobber previous error status */
\r
156 @@ -1207,7 +1211,7 @@ notmuch_database_compact (unused (const char *path),
\r
157 unused (notmuch_compact_status_cb_t status_cb),
\r
158 unused (void *closure))
\r
160 - fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
\r
161 + _notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n");
\r
162 return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
\r
165 @@ -1485,7 +1489,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
168 if (private_status) {
\r
170 + _notmuch_database_log (notmuch,
\r
171 "Upgrade failed while creating ghost messages.\n");
\r
172 status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
\r
174 @@ -1535,7 +1539,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
\r
176 (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
\r
177 } catch (const Xapian::Error &error) {
\r
178 - fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",
\r
179 + _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",
\r
180 error.get_msg().c_str());
\r
181 notmuch->exception_reported = TRUE;
\r
182 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
183 @@ -1569,7 +1573,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)
\r
184 if (thresh && atoi (thresh) == 1)
\r
186 } catch (const Xapian::Error &error) {
\r
187 - fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",
\r
188 + _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",
\r
189 error.get_msg().c_str());
\r
190 notmuch->exception_reported = TRUE;
\r
191 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
192 @@ -1815,7 +1819,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,
\r
193 *directory = _notmuch_directory_create (notmuch, path,
\r
194 NOTMUCH_FIND_LOOKUP, &status);
\r
195 } catch (const Xapian::Error &error) {
\r
196 - fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
\r
197 + _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",
\r
198 error.get_msg().c_str());
\r
199 notmuch->exception_reported = TRUE;
\r
200 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
201 @@ -2397,7 +2401,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
203 _notmuch_message_sync (message);
\r
204 } catch (const Xapian::Error &error) {
\r
205 - fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
\r
206 + _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",
\r
207 error.get_msg().c_str());
\r
208 notmuch->exception_reported = TRUE;
\r
209 ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
210 @@ -2489,7 +2493,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
\r
211 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
213 } catch (const Xapian::Error &error) {
\r
214 - fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",
\r
215 + _notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n",
\r
216 error.get_msg().c_str());
\r
217 notmuch->exception_reported = TRUE;
\r
218 status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
219 @@ -2542,7 +2546,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
\r
220 _notmuch_string_list_sort (tags);
\r
221 return _notmuch_tags_create (db, tags);
\r
222 } catch (const Xapian::Error &error) {
\r
223 - fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",
\r
224 + _notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n",
\r
225 error.get_msg().c_str());
\r
226 db->exception_reported = TRUE;
\r
228 diff --git a/lib/directory.cc b/lib/directory.cc
\r
229 index 8daaec8..b836ea2 100644
\r
230 --- a/lib/directory.cc
\r
231 +++ b/lib/directory.cc
\r
232 @@ -186,7 +186,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
\r
233 directory->mtime = Xapian::sortable_unserialise (
\r
234 directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));
\r
235 } catch (const Xapian::Error &error) {
\r
237 + _notmuch_database_log (notmuch,
\r
238 "A Xapian exception occurred creating a directory: %s.\n",
\r
239 error.get_msg().c_str());
\r
240 notmuch->exception_reported = TRUE;
\r
241 @@ -228,7 +228,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
\r
243 db->replace_document (directory->document_id, directory->doc);
\r
244 } catch (const Xapian::Error &error) {
\r
246 + _notmuch_database_log (notmuch,
\r
247 "A Xapian exception occurred setting directory mtime: %s.\n",
\r
248 error.get_msg().c_str());
\r
249 notmuch->exception_reported = TRUE;
\r
250 diff --git a/lib/index.cc b/lib/index.cc
\r
251 index c88ed8d..e81aa81 100644
\r
254 @@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message,
\r
255 const char *charset;
\r
258 - fprintf (stderr, "Warning: Not indexing empty mime part.\n");
\r
259 + _notmuch_database_log (_notmuch_message_database (message),
\r
260 + "Warning: Not indexing empty mime part.\n");
\r
264 @@ -344,7 +345,8 @@ _index_mime_part (notmuch_message_t *message,
\r
268 - fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
\r
269 + _notmuch_database_log (_notmuch_message_database (message),
\r
270 + "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
\r
272 if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
\r
273 /* Don't index encrypted parts. */
\r
274 @@ -367,8 +369,9 @@ _index_mime_part (notmuch_message_t *message,
\r
277 if (! (GMIME_IS_PART (part))) {
\r
278 - fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",
\r
279 - g_type_name (G_OBJECT_TYPE (part)));
\r
280 + _notmuch_database_log (_notmuch_message_database (message),
\r
281 + "Warning: Not indexing unknown mime part: %s.\n",
\r
282 + g_type_name (G_OBJECT_TYPE (part)));
\r
286 diff --git a/lib/message.cc b/lib/message.cc
\r
287 index b84e5e1..a8ca988 100644
\r
288 --- a/lib/message.cc
\r
289 +++ b/lib/message.cc
\r
290 @@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
\r
292 doc_id = _notmuch_database_generate_doc_id (notmuch);
\r
293 } catch (const Xapian::Error &error) {
\r
294 - fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
\r
295 + _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
\r
296 error.get_msg().c_str());
\r
297 notmuch->exception_reported = TRUE;
\r
298 *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
\r
299 @@ -467,7 +467,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)
\r
300 return talloc_strdup (message, value.c_str ());
\r
302 } catch (Xapian::Error &error) {
\r
303 - fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
\r
304 + _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",
\r
305 error.get_msg().c_str());
\r
306 message->notmuch->exception_reported = TRUE;
\r
308 @@ -921,7 +921,7 @@ notmuch_message_get_date (notmuch_message_t *message)
\r
310 value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
\r
311 } catch (Xapian::Error &error) {
\r
312 - fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",
\r
313 + _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",
\r
314 error.get_msg().c_str());
\r
315 message->notmuch->exception_reported = TRUE;
\r
317 diff --git a/lib/query.cc b/lib/query.cc
\r
318 index 57aa6d2..9cedb6a 100644
\r
321 @@ -296,9 +296,12 @@ notmuch_query_search_messages_st (notmuch_query_t *query,
\r
322 return NOTMUCH_STATUS_SUCCESS;
\r
324 } catch (const Xapian::Error &error) {
\r
325 - fprintf (stderr, "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,
\r
329 + "A Xapian exception occurred performing query: %s\n"
\r
330 + "Query string was: %s\n",
\r
331 + error.get_msg().c_str(),
\r
332 + query->query_string);
\r
334 notmuch->exception_reported = TRUE;
\r
335 talloc_free (messages);
\r
336 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
337 @@ -597,9 +600,12 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
338 count = mset.get_matches_estimated();
\r
340 } catch (const Xapian::Error &error) {
\r
341 - fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
342 - error.get_msg().c_str());
\r
343 - fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
344 + _notmuch_database_log (notmuch,
\r
345 + "A Xapian exception occurred performing query: %s\n"
\r
346 + "Query string was: %s\n",
\r
347 + error.get_msg().c_str(),
\r
348 + query->query_string);
\r
353 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
\r
354 index c2964cb..ec7552a 100755
\r
355 --- a/test/T560-lib-error.sh
\r
356 +++ b/test/T560-lib-error.sh
\r
357 @@ -66,6 +66,9 @@ int main (int argc, char** argv)
\r
358 fprintf (stderr, "error opening database: %d\n", stat);
\r
360 stat = notmuch_database_add_message (db, "/dev/null", NULL);
\r
362 + fputs (notmuch_database_status_string (db), stderr);
\r
366 cat <<EOF >EXPECTED
\r
367 @@ -118,8 +121,9 @@ int main (int argc, char** argv)
\r
369 cat <<EOF >EXPECTED
\r
372 Path already exists: CWD/mail
\r
376 test_expect_equal_file EXPECTED OUTPUT
\r