From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id CIyQF78w+16ecgAA0tVLHw (envelope-from ) for ; Tue, 30 Jun 2020 12:31:59 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id iPFjE78w+14HGwAAB5/wlQ (envelope-from ) for ; Tue, 30 Jun 2020 12:31:59 +0000 Received: from arlo.cworth.org (arlo.cworth.org [50.126.95.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D8A4E940701 for ; Tue, 30 Jun 2020 12:31:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 0401F6DE13DE; Tue, 30 Jun 2020 05:31:57 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0lhLy7CKrHKT; Tue, 30 Jun 2020 05:31:56 -0700 (PDT) Received: from arlo.cworth.org (localhost [IPv6:::1]) by arlo.cworth.org (Postfix) with ESMTP id BC35F6DE0F88; Tue, 30 Jun 2020 05:31:55 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 1A8206DE0F88 for ; Tue, 30 Jun 2020 05:31:54 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ALEvaRCx8QNI for ; Tue, 30 Jun 2020 05:31:53 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTP id 807096DE0F76 for ; Tue, 30 Jun 2020 05:31:53 -0700 (PDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 391C76141D; Tue, 30 Jun 2020 08:31:53 -0400 (EDT) Received: (nullmailer pid 2275044 invoked by uid 1000); Tue, 30 Jun 2020 12:31:51 -0000 Resent-To: notmuch@notmuchmail.org Resent-From: David Bremner Resent-Date: Tue, 30 Jun 2020 09:31:51 -0300 Resent-Message-ID: <87y2o4ivk8.fsf@tethera.net> Received: by fethera.tethera.net (Postfix, from userid 1001) id 633216142B; Mon, 29 Jun 2020 21:14:33 -0400 (EDT) Received: (nullmailer pid 612642 invoked by uid 1000); Tue, 30 Jun 2020 01:14:18 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/4] lib: catch error from closed db in n_m_get_message_id Date: Mon, 29 Jun 2020 22:14:09 -0300 Message-Id: <20200630011411.612552-3-david@tethera.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200630011411.612552-1-david@tethera.net> References: <20200630011411.612552-1-david@tethera.net> MIME-Version: 1.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: notmuch-bounces@notmuchmail.org Sender: "notmuch" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 50.126.95.6 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: -0.01 X-TUID: evKpY+GoMw+Y By catching it at the library top level, we can return an error value. --- lib/message.cc | 23 +++++++++++++++++++---- lib/notmuch.h | 5 ++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 0fa0eb3a..b7a64b1c 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -90,6 +90,18 @@ _notmuch_message_destructor (notmuch_message_t *message) return 0; } +#define LOG_XAPIAN_EXCEPTION(message, error) _log_xapian_exception (__location__, message, error) + +static void +_log_xapian_exception (const char *where, notmuch_message_t *message, const Xapian::Error error) { + notmuch_database_t *notmuch = notmuch_message_get_database (message); + _notmuch_database_log (notmuch, + "A Xapian exception occurred %s retrieving %s : %s\n", + where, + error.get_msg ().c_str ()); + notmuch->exception_reported = true; +} + static notmuch_message_t * _notmuch_message_create_for_document (const void *talloc_owner, notmuch_database_t *notmuch, @@ -447,9 +459,6 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message, void *field) if (status != NOTMUCH_STATUS_SUCCESS) INTERNAL_ERROR ("unhandled error from notmuch_database_reopen: %s\n", notmuch_status_to_string (status)); - } catch (const Xapian::Error &error) { - INTERNAL_ERROR ("A Xapian exception occurred fetching message metadata: %s\n", - error.get_msg ().c_str ()); } } message->last_view = message->notmuch->view; @@ -507,7 +516,13 @@ _notmuch_message_get_doc_id (notmuch_message_t *message) const char * notmuch_message_get_message_id (notmuch_message_t *message) { - _notmuch_message_ensure_metadata (message, message->message_id); + try { + _notmuch_message_ensure_metadata (message, message->message_id); + } catch (const Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + return NULL; + } + if (! message->message_id) INTERNAL_ERROR ("Message with document ID of %u has no message ID.\n", message->doc_id); diff --git a/lib/notmuch.h b/lib/notmuch.h index ceb5a018..0dc89547 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1363,9 +1363,8 @@ notmuch_message_get_database (const notmuch_message_t *message); * message is valid, (which is until the query from which it derived * is destroyed). * - * This function will not return NULL since Notmuch ensures that every - * message has a unique message ID, (Notmuch will generate an ID for a - * message if the original file does not contain one). + * This function will return NULL if triggers an unhandled Xapian + * exception. */ const char * notmuch_message_get_message_id (notmuch_message_t *message); -- 2.27.0