Catch and optionally print about exception at database->flush.

If an earlier exception occurred, then it's not unexpected for the
flush to fail as well. So in that case, we'll silently catch the
exception. Otherwise, make some noise about things going wrong at the
time of flush.
This commit is contained in:
Carl Worth 2009-11-22 03:54:20 +01:00
parent 717279fbcf
commit e2341cbc09
4 changed files with 15 additions and 2 deletions

View file

@ -26,6 +26,7 @@
#include <xapian.h> #include <xapian.h>
struct _notmuch_database { struct _notmuch_database {
notmuch_bool_t exception_reported;
char *path; char *path;
notmuch_database_mode_t mode; notmuch_database_mode_t mode;
Xapian::Database *xapian_db; Xapian::Database *xapian_db;

View file

@ -480,6 +480,7 @@ notmuch_database_open (const char *path,
} }
notmuch = talloc (NULL, notmuch_database_t); notmuch = talloc (NULL, notmuch_database_t);
notmuch->exception_reported = FALSE;
notmuch->path = talloc_strdup (notmuch, path); notmuch->path = talloc_strdup (notmuch, path);
if (notmuch->path[strlen (notmuch->path) - 1] == '/') if (notmuch->path[strlen (notmuch->path) - 1] == '/')
@ -530,8 +531,15 @@ notmuch_database_open (const char *path,
void void
notmuch_database_close (notmuch_database_t *notmuch) notmuch_database_close (notmuch_database_t *notmuch)
{ {
if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE) try {
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush (); if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
} catch (const Xapian::Error &error) {
if (! notmuch->exception_reported) {
fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
error.get_msg().c_str());
}
}
delete notmuch->term_gen; delete notmuch->term_gen;
delete notmuch->query_parser; delete notmuch->query_parser;
@ -611,6 +619,7 @@ notmuch_database_set_timestamp (notmuch_database_t *notmuch,
} catch (const Xapian::Error &error) { } catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred setting timestamp: %s.\n", fprintf (stderr, "A Xapian exception occurred setting timestamp: %s.\n",
error.get_msg().c_str()); error.get_msg().c_str());
notmuch->exception_reported = TRUE;
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
} }
@ -985,6 +994,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
} catch (const Xapian::Error &error) { } catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred adding message: %s.\n", fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
error.get_description().c_str()); error.get_description().c_str());
notmuch->exception_reported = TRUE;
ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION; ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
goto DONE; goto DONE;
} }

View file

@ -201,6 +201,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
} catch (const Xapian::Error &error) { } catch (const Xapian::Error &error) {
fprintf (stderr, "A Xapian exception occurred creating message: %s\n", fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
error.get_msg().c_str()); error.get_msg().c_str());
notmuch->exception_reported = TRUE;
*status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; *status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
return NULL; return NULL;
} }

View file

@ -152,6 +152,7 @@ notmuch_query_search_messages (notmuch_query_t *query,
fprintf (stderr, "A Xapian exception occurred performing query: %s\n", fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
error.get_msg().c_str()); error.get_msg().c_str());
fprintf (stderr, "Query string was: %s\n", query->query_string); fprintf (stderr, "Query string was: %s\n", query->query_string);
notmuch->exception_reported = TRUE;
} }
return _notmuch_messages_create (message_list); return _notmuch_messages_create (message_list);