From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id IMa7HLs0Dl8QNwAA0tVLHw (envelope-from ) for ; Tue, 14 Jul 2020 22:42:03 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id KE+2GLs0Dl9wdQAA1q6Kng (envelope-from ) for ; Tue, 14 Jul 2020 22:42:03 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DCE60940667 for ; Tue, 14 Jul 2020 22:42:02 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1608620352; Tue, 14 Jul 2020 18:41:48 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 378FC1FBDC for ; Tue, 14 Jul 2020 18:41:42 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 232CE5FFD4; Tue, 14 Jul 2020 18:41:42 -0400 (EDT) Received: (nullmailer pid 717936 invoked by uid 1000); Tue, 14 Jul 2020 22:41:22 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 4/4] lib/n_d_get_version: catch exceptions and clarify the API Date: Tue, 14 Jul 2020 19:41:19 -0300 Message-Id: <20200714224119.717845-5-david@tethera.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714224119.717845-1-david@tethera.net> References: <20200714224119.717845-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WEHTGW2IVNNFQHLP5ZCPMQWKAZPR4D6G X-Message-ID-Hash: WEHTGW2IVNNFQHLP5ZCPMQWKAZPR4D6G X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 1.53 X-TUID: SMK/hC6bSFB2 notmuch_database_get_version previously returned 0 on some errors, but did not document this. Luckily 0 is not a valid database version. --- lib/database.cc | 19 ++++++++++++++++++- lib/notmuch.h | 3 +++ test/T562-lib-database.sh | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index cfb19ccb..27861970 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 %s accessing %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; diff --git a/lib/notmuch.h b/lib/notmuch.h index 97ebc17d..7ee0507a 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -431,6 +431,8 @@ notmuch_database_get_path (notmuch_database_t *database); /** * Return the database format version of the given database. + * + * @retval 0 on error */ unsigned int notmuch_database_get_version (notmuch_database_t *database); @@ -444,6 +446,7 @@ notmuch_database_get_version (notmuch_database_t *database); * fail with NOTMUCH_STATUS_UPGRADE_REQUIRED. This always returns * FALSE for a read-only database because there's no way to upgrade a * read-only database. + * */ notmuch_bool_t notmuch_database_needs_upgrade (notmuch_database_t *database); diff --git a/test/T562-lib-database.sh b/test/T562-lib-database.sh index b8fba7d6..c9705b13 100755 --- a/test/T562-lib-database.sh +++ b/test/T562-lib-database.sh @@ -68,7 +68,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "get version with closed db" -test_subtest_known_broken cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { unsigned int version; -- 2.27.0