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 E2634429E3A
\r
6 for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:52 -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 T97lnoXouX8G for <notmuch@notmuchmail.org>;
\r
16 Fri, 27 Mar 2015 15:14:50 -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 F2B3B429E36
\r
22 for <notmuch@notmuchmail.org>; Fri, 27 Mar 2015 15:14:49 -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 1YbcW0-0000Fh-SY; Fri, 27 Mar 2015 22:14:08 +0000
\r
26 Received: (nullmailer pid 1819 invoked by uid 1000); Fri, 27 Mar 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [Patch v6 7/8] lib: replace almost all fprintfs in library with
\r
32 Date: Fri, 27 Mar 2015 23:11:59 +0100
\r
33 Message-Id: <1427494320-1483-8-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 2.1.4
\r
35 In-Reply-To: <1427494320-1483-1-git-send-email-david@tethera.net>
\r
36 References: <1427494320-1483-1-git-send-email-david@tethera.net>
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\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: Fri, 27 Mar 2015 22:14:53 -0000
\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
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 | 18 ++++++++++++------
\r
62 test/T560-lib-error.sh | 6 +++++-
\r
63 6 files changed, 50 insertions(+), 33 deletions(-)
\r
65 diff --git a/lib/database.cc b/lib/database.cc
\r
66 index c114765..e40674a 100644
\r
67 --- a/lib/database.cc
\r
68 +++ b/lib/database.cc
\r
69 @@ -473,7 +473,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
\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 @@ -719,7 +719,7 @@ notmuch_status_t
\r
79 _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\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
87 @@ -1015,7 +1015,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
96 @@ -1147,12 +1147,12 @@ notmuch_database_compact (const char *path,
\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
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
109 ret = NOTMUCH_STATUS_FILE_ERROR;
\r
111 @@ -1172,20 +1172,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
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
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
135 @@ -1193,7 +1193,7 @@ notmuch_database_compact (const char *path,
\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
144 @@ -1204,6 +1204,10 @@ notmuch_database_compact (const char *path,
\r
146 notmuch_status_t ret2;
\r
148 + const char *str = notmuch_database_status_string (notmuch);
\r
149 + if (status_cb && str)
\r
150 + status_cb (str, closure);
\r
152 ret2 = notmuch_database_destroy (notmuch);
\r
154 /* don't clobber previous error status */
\r
155 @@ -1222,7 +1226,7 @@ notmuch_database_compact (unused (const char *path),
\r
156 unused (notmuch_compact_status_cb_t status_cb),
\r
157 unused (void *closure))
\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
164 @@ -1500,7 +1504,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
167 if (private_status) {
\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
173 @@ -1550,7 +1554,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
\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 @@ -1584,7 +1588,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)
\r
183 if (thresh && atoi (thresh) == 1)
\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 @@ -1830,7 +1834,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 @@ -2412,7 +2416,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\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 @@ -2504,7 +2508,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
\r
210 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
\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 @@ -2557,7 +2561,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
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
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
242 db->replace_document (directory->document_id, directory->doc);
\r
243 } catch (const Xapian::Error &error) {
\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
253 @@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message,
\r
254 const char *charset;
\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
263 @@ -344,7 +345,8 @@ _index_mime_part (notmuch_message_t *message,
\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
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
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
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
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
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
307 @@ -921,7 +921,7 @@ notmuch_message_get_date (notmuch_message_t *message)
\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
316 diff --git a/lib/query.cc b/lib/query.cc
\r
317 index 57aa6d2..9cedb6a 100644
\r
320 @@ -296,9 +296,12 @@ notmuch_query_search_messages_st (notmuch_query_t *query,
\r
321 return NOTMUCH_STATUS_SUCCESS;
\r
323 } catch (const Xapian::Error &error) {
\r
324 - fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
\r
325 - error.get_msg().c_str());
\r
326 - fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
327 + _notmuch_database_log (notmuch,
\r
328 + "A Xapian exception occurred performing query: %s\n"
\r
329 + "Query string was: %s\n",
\r
330 + error.get_msg().c_str(),
\r
331 + query->query_string);
\r
333 notmuch->exception_reported = TRUE;
\r
334 talloc_free (messages);
\r
335 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
336 @@ -597,9 +600,12 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
337 count = mset.get_matches_estimated();
\r
339 } catch (const Xapian::Error &error) {
\r
340 - fprintf (stderr, "A Xapian exception occurred: %s\n",
\r
341 - error.get_msg().c_str());
\r
342 - fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
343 + _notmuch_database_log (notmuch,
\r
344 + "A Xapian exception occurred performing query: %s\n"
\r
345 + "Query string was: %s\n",
\r
346 + error.get_msg().c_str(),
\r
347 + query->query_string);
\r
352 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
\r
353 index f1ca543..67a5e8d 100755
\r
354 --- a/test/T560-lib-error.sh
\r
355 +++ b/test/T560-lib-error.sh
\r
356 @@ -101,6 +101,9 @@ int main (int argc, char** argv)
\r
357 fprintf (stderr, "error opening database: %d\n", stat);
\r
359 stat = notmuch_database_add_message (db, "/dev/null", NULL);
\r
361 + fputs (notmuch_database_status_string (db), stderr);
\r
365 cat <<'EOF' >EXPECTED
\r
366 @@ -153,8 +156,9 @@ int main (int argc, char** argv)
\r
368 cat <<'EOF' >EXPECTED
\r
371 Path already exists: CWD/mail
\r
375 test_expect_equal_file EXPECTED OUTPUT
\r