This is not supposed to change any functionality from an end user
point of view. Note that it will eliminate some output to stderr. The
query debugging output is left as is; it doesn't really fit with the
current primitive logging model. The remaining "bad" fprintf will need
an internal API change.
return NOTMUCH_STATUS_SUCCESS;
} catch (const Xapian::Error &error) {
return NOTMUCH_STATUS_SUCCESS;
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
+ _notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*message_ret = NULL;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*message_ret = NULL;
_notmuch_database_ensure_writable (notmuch_database_t *notmuch)
{
if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
_notmuch_database_ensure_writable (notmuch_database_t *notmuch)
{
if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
- fprintf (stderr, "Cannot write to a read-only database.\n");
+ _notmuch_database_log (notmuch, "Cannot write to a read-only database.\n");
return NOTMUCH_STATUS_READ_ONLY_DATABASE;
}
return NOTMUCH_STATUS_READ_ONLY_DATABASE;
}
} catch (const Xapian::Error &error) {
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
if (! notmuch->exception_reported) {
} catch (const Xapian::Error &error) {
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
if (! notmuch->exception_reported) {
- fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",
+ _notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n",
error.get_msg().c_str());
}
}
error.get_msg().c_str());
}
}
}
if (stat (backup_path, &statbuf) != -1) {
}
if (stat (backup_path, &statbuf) != -1) {
- fprintf (stderr, "Path already exists: %s\n", backup_path);
+ _notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path);
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
if (errno != ENOENT) {
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
if (errno != ENOENT) {
- fprintf (stderr, "Unknown error while stat()ing path: %s\n",
+ _notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n",
strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
compactor.set_destdir (compact_xapian_path);
compactor.compact ();
} catch (const Xapian::Error &error) {
compactor.set_destdir (compact_xapian_path);
compactor.compact ();
} catch (const Xapian::Error &error) {
- fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str());
+ _notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str());
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
goto DONE;
}
if (rename (xapian_path, backup_path)) {
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
goto DONE;
}
if (rename (xapian_path, backup_path)) {
- fprintf (stderr, "Error moving %s to %s: %s\n",
+ _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
xapian_path, backup_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
if (rename (compact_xapian_path, xapian_path)) {
xapian_path, backup_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
if (rename (compact_xapian_path, xapian_path)) {
- fprintf (stderr, "Error moving %s to %s: %s\n",
+ _notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
compact_xapian_path, xapian_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
compact_xapian_path, xapian_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
if (! keep_backup) {
if (rmtree (backup_path)) {
if (! keep_backup) {
if (rmtree (backup_path)) {
- fprintf (stderr, "Error removing old database %s: %s\n",
+ _notmuch_database_log (notmuch, "Error removing old database %s: %s\n",
backup_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
backup_path, strerror (errno));
ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
if (notmuch) {
notmuch_status_t ret2;
if (notmuch) {
notmuch_status_t ret2;
+ const char *str = notmuch_database_status_string (notmuch);
+ if (status_cb && str)
+ status_cb (str, closure);
+
ret2 = notmuch_database_destroy (notmuch);
/* don't clobber previous error status */
ret2 = notmuch_database_destroy (notmuch);
/* don't clobber previous error status */
unused (notmuch_compact_status_cb_t status_cb),
unused (void *closure))
{
unused (notmuch_compact_status_cb_t status_cb),
unused (void *closure))
{
- fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
+ _notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n");
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
}
#endif
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
}
#endif
+ _notmuch_database_log (notmuch,
"Upgrade failed while creating ghost messages.\n");
status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
goto DONE;
"Upgrade failed while creating ghost messages.\n");
status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
goto DONE;
try {
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
} catch (const Xapian::Error &error) {
try {
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",
+ _notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
if (thresh && atoi (thresh) == 1)
db->flush ();
} catch (const Xapian::Error &error) {
if (thresh && atoi (thresh) == 1)
db->flush ();
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",
+ _notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
*directory = _notmuch_directory_create (notmuch, path,
NOTMUCH_FIND_LOOKUP, &status);
} catch (const Xapian::Error &error) {
*directory = _notmuch_directory_create (notmuch, path,
NOTMUCH_FIND_LOOKUP, &status);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
+ _notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
_notmuch_message_sync (message);
} catch (const Xapian::Error &error) {
_notmuch_message_sync (message);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
+ _notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
}
} catch (const Xapian::Error &error) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
}
} catch (const Xapian::Error &error) {
- fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",
+ _notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
_notmuch_string_list_sort (tags);
return _notmuch_tags_create (db, tags);
} catch (const Xapian::Error &error) {
_notmuch_string_list_sort (tags);
return _notmuch_tags_create (db, tags);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",
+ _notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n",
error.get_msg().c_str());
db->exception_reported = TRUE;
return NULL;
error.get_msg().c_str());
db->exception_reported = TRUE;
return NULL;
directory->mtime = Xapian::sortable_unserialise (
directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));
} catch (const Xapian::Error &error) {
directory->mtime = Xapian::sortable_unserialise (
directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));
} catch (const Xapian::Error &error) {
+ _notmuch_database_log (notmuch,
"A Xapian exception occurred creating a directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
"A Xapian exception occurred creating a directory: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
db->replace_document (directory->document_id, directory->doc);
} catch (const Xapian::Error &error) {
db->replace_document (directory->document_id, directory->doc);
} catch (const Xapian::Error &error) {
+ _notmuch_database_log (notmuch,
"A Xapian exception occurred setting directory mtime: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
"A Xapian exception occurred setting directory mtime: %s.\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
const char *charset;
if (! part) {
const char *charset;
if (! part) {
- fprintf (stderr, "Warning: Not indexing empty mime part.\n");
+ _notmuch_database_log (_notmuch_message_database (message),
+ "Warning: Not indexing empty mime part.\n");
if (i == 1)
continue;
if (i > 1)
if (i == 1)
continue;
if (i > 1)
- fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
+ _notmuch_database_log (_notmuch_message_database (message),
+ "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
}
if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
/* Don't index encrypted parts. */
}
if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
/* Don't index encrypted parts. */
}
if (! (GMIME_IS_PART (part))) {
}
if (! (GMIME_IS_PART (part))) {
- fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",
- g_type_name (G_OBJECT_TYPE (part)));
+ _notmuch_database_log (_notmuch_message_database (message),
+ "Warning: Not indexing unknown mime part: %s.\n",
+ g_type_name (G_OBJECT_TYPE (part)));
doc_id = _notmuch_database_generate_doc_id (notmuch);
} catch (const Xapian::Error &error) {
doc_id = _notmuch_database_generate_doc_id (notmuch);
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
return talloc_strdup (message, value.c_str ());
} catch (Xapian::Error &error) {
return talloc_strdup (message, value.c_str ());
} catch (Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return NULL;
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return NULL;
try {
value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
} catch (Xapian::Error &error) {
try {
value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
} catch (Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return 0;
error.get_msg().c_str());
message->notmuch->exception_reported = TRUE;
return 0;
return NOTMUCH_STATUS_SUCCESS;
} catch (const Xapian::Error &error) {
return NOTMUCH_STATUS_SUCCESS;
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
- error.get_msg().c_str());
- fprintf (stderr, "Query string was: %s\n", query->query_string);
+ _notmuch_database_log (notmuch,
+ "A Xapian exception occurred performing query: %s\n"
+ "Query string was: %s\n",
+ error.get_msg().c_str(),
+ query->query_string);
+
notmuch->exception_reported = TRUE;
talloc_free (messages);
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
notmuch->exception_reported = TRUE;
talloc_free (messages);
return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
count = mset.get_matches_estimated();
} catch (const Xapian::Error &error) {
count = mset.get_matches_estimated();
} catch (const Xapian::Error &error) {
- fprintf (stderr, "A Xapian exception occurred: %s\n",
- error.get_msg().c_str());
- fprintf (stderr, "Query string was: %s\n", query->query_string);
+ _notmuch_database_log (notmuch,
+ "A Xapian exception occurred performing query: %s\n"
+ "Query string was: %s\n",
+ error.get_msg().c_str(),
+ query->query_string);
+
fprintf (stderr, "error opening database: %d\n", stat);
}
stat = notmuch_database_add_message (db, "/dev/null", NULL);
fprintf (stderr, "error opening database: %d\n", stat);
}
stat = notmuch_database_add_message (db, "/dev/null", NULL);
+ if (stat)
+ fputs (notmuch_database_status_string (db), stderr);
+
}
EOF
cat <<'EOF' >EXPECTED
}
EOF
cat <<'EOF' >EXPECTED
EOF
cat <<'EOF' >EXPECTED
== stdout ==
EOF
cat <<'EOF' >EXPECTED
== stdout ==
Path already exists: CWD/mail
Path already exists: CWD/mail
EOF
test_expect_equal_file EXPECTED OUTPUT
EOF
test_expect_equal_file EXPECTED OUTPUT