aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-07-14 19:31:10 -0300
committerDavid Bremner <david@tethera.net>2020-07-22 19:52:55 -0300
commitab456541924dcb1e1c6d6c7ba1781011e3453f27 (patch)
tree7d82636f1b05f59ec814040c19036377314291a9 /lib/database.cc
parent095d3d7134f5668b96cf1d70997d3f110b03c898 (diff)
lib/n_d_get_version: catch exceptions and clarify the API
notmuch_database_get_version previously returned 0 on some errors, but did not document this. Luckily 0 is not a valid database version.
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/database.cc b/lib/database.cc
index cfb19ccb..8ec91987 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -58,6 +58,17 @@ typedef struct {
#define DB_ACTION Xapian::DB_CREATE_OR_OPEN
#endif
+#define LOG_XAPIAN_EXCEPTION(message, error) _log_xapian_exception (__location__, message, error)
+
+static void
+_log_xapian_exception (const char *where, notmuch_database_t *notmuch, const Xapian::Error error) {
+ _notmuch_database_log (notmuch,
+ "A Xapian exception occurred at %s: %s\n",
+ where,
+ error.get_msg ().c_str ());
+ notmuch->exception_reported = true;
+}
+
/* Here's the current schema for our database (for NOTMUCH_DATABASE_VERSION):
*
* We currently have three different types of documents (mail, ghost,
@@ -1360,7 +1371,13 @@ notmuch_database_get_version (notmuch_database_t *notmuch)
const char *str;
char *end;
- version_string = notmuch->xapian_db->get_metadata ("version");
+ try {
+ version_string = notmuch->xapian_db->get_metadata ("version");
+ } catch (const Xapian::Error &error) {
+ LOG_XAPIAN_EXCEPTION (notmuch, error);
+ return 0;
+ }
+
if (version_string.empty ())
return 0;