From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id CL69HGxwHV9ICQAA0tVLHw (envelope-from ) for ; Sun, 26 Jul 2020 12:00:44 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QFR2GGxwHV+uewAAbx9fmQ (envelope-from ) for ; Sun, 26 Jul 2020 12:00:44 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 264929403AE for ; Sun, 26 Jul 2020 12:00:44 +0000 (UTC) Received: from [144.217.243.247] (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 73CFC27BE4; Sun, 26 Jul 2020 08:00:20 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 1C93527B9C for ; Sun, 26 Jul 2020 08:00:07 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0DC8B60AB8; Sun, 26 Jul 2020 08:00:07 -0400 (EDT) Received: (nullmailer pid 1448356 invoked by uid 1000); Sun, 26 Jul 2020 11:59:43 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 05/13] lib: catch exceptions in n_directory_get_child_directories Date: Sun, 26 Jul 2020 08:59:23 -0300 Message-Id: <20200726115931.1448056-6-david@tethera.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200726115931.1448056-1-david@tethera.net> References: <20200726115931.1448056-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: EYTTYV4NALDFN5EIZPGL6XWHMSEC6KXT X-Message-ID-Hash: EYTTYV4NALDFN5EIZPGL6XWHMSEC6KXT 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 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: 0.03 X-TUID: APInfrx0psBV Also clarify API in error case. --- lib/directory.cc | 23 ++++++++++++++++++++--- lib/notmuch.h | 2 ++ test/T563-lib-directory.sh | 1 - 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/directory.cc b/lib/directory.cc index 09b49245..eb59d24d 100644 --- a/lib/directory.cc +++ b/lib/directory.cc @@ -49,6 +49,19 @@ struct _notmuch_directory { time_t mtime; }; +#define LOG_XAPIAN_EXCEPTION(directory, error) _log_xapian_exception (__location__, directory, error) + +static void +_log_xapian_exception (const char *where, notmuch_directory_t *dir, const Xapian::Error error) { + notmuch_database_t *notmuch = dir->notmuch; + _notmuch_database_log (notmuch, + "A Xapian exception occurred at %s: %s\n", + where, + error.get_msg ().c_str ()); + notmuch->exception_reported = true; +} + + /* We end up having to call the destructor explicitly because we had * to use "placement new" in order to initialize C++ objects within a * block that we allocated with talloc. So C++ is making talloc @@ -270,14 +283,18 @@ notmuch_filenames_t * notmuch_directory_get_child_directories (notmuch_directory_t *directory) { char *term; - notmuch_filenames_t *child_directories; + notmuch_filenames_t *child_directories = NULL; term = talloc_asprintf (directory, "%s%u:", _find_prefix ("directory-direntry"), directory->document_id); - child_directories = _create_filenames_for_terms_with_prefix (directory, - directory->notmuch, term); + try { + child_directories = _create_filenames_for_terms_with_prefix (directory, + directory->notmuch, term); + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (directory, error); + } talloc_free (term); diff --git a/lib/notmuch.h b/lib/notmuch.h index f9e9cc41..03db3b24 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -2158,6 +2158,8 @@ notmuch_directory_get_child_files (notmuch_directory_t *directory); * * The returned filenames will be the basename-entries only (not * complete paths). + * + * Returns NULL if it triggers a Xapian exception */ notmuch_filenames_t * notmuch_directory_get_child_directories (notmuch_directory_t *directory); diff --git a/test/T563-lib-directory.sh b/test/T563-lib-directory.sh index e9e4cd0f..4d8b7e82 100755 --- a/test/T563-lib-directory.sh +++ b/test/T563-lib-directory.sh @@ -41,7 +41,6 @@ cat <<'EOF' > c_tail EOF test_begin_subtest "get child directories for a closed db" -test_subtest_known_broken cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { notmuch_filenames_t *children; -- 2.27.0