From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sPhDJwsGjGNFYgAAbAwnHQ (envelope-from ) for ; Sun, 04 Dec 2022 03:29:31 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id kN9VJgsGjGM+uwAAG6o9tA (envelope-from ) for ; Sun, 04 Dec 2022 03:29:31 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 66F5F10199 for ; Sun, 4 Dec 2022 03:29:31 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id AB0E55FC03; Sun, 4 Dec 2022 02:29:15 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5026C5FB4C for ; Sun, 4 Dec 2022 02:29:13 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id BAF1C5FBC4; Sat, 3 Dec 2022 21:29:12 -0500 (EST) Received: (nullmailer pid 1551668 invoked by uid 1000); Sun, 04 Dec 2022 02:29:09 -0000 From: David Bremner To: Thomas Schneider , notmuch@notmuchmail.org Subject: [PATCH 3/3] lib/message: move xapian call inside try/catch block in _n_m_delete Date: Sat, 3 Dec 2022 22:28:57 -0400 Message-Id: <20221204022857.1551514-4-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20221204022857.1551514-1-david@tethera.net> References: <20221204022857.1551514-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WM4J74SC6TFQKZ2SUZG3PAE6HZHUWI45 X-Message-ID-Hash: WM4J74SC6TFQKZ2SUZG3PAE6HZHUWI45 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; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1670120971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=kk2yA15slsN3zJYEUaOpoIB4LwN7BHBaVgxffBn7mzE=; b=AmHhmdRyVMzUfMcqXpSkAx6o5BhTrI94+KHunh+kqPmRgEbnJ7Qk4GA/f4Y7DhJiPdyunF 3LlTAGUUhIRcjq+GpZVFc9xu3pVDDATnGwcvohOykCOlx0y3Fy7V8FpV42MKKDwzH24ULJ XVjL+qQSeTA/81FbIvEGyxP7IdJx/25wIyKxrw8knv7BK757EaDW0g/7r+IGh7I1E+PKb5 tE+xwOSUtxH9ETec9N395P3hFyZuN2/pufyUbdul1AcoDILdeU5B/GWONjXzdCcaNFA95u bSWJ7Xg0hzaqAE962yXB+WeCdPmyCPWobrU73ptX4ds+sjgbOmhJfRoEwS13KQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1670120971; a=rsa-sha256; cv=none; b=uogKNaXvIjILdkhxWA392ybilK4RbXyBKzuo4UGCxbpBIwleTQXUd9PoXiHntJBPdM/HbW GiU3mQZd9m4BMrCZjdHSO7F9PjQnXexDPKZ/sDb7mkUxsGlS3dLQed8UL0Ex59a6jhBBRs A7tvXvFxUG+eRTsKqR6o4TNM/1QI2qt+LF7wHUljH05t3t/i+Fn515nWuuLMe0qHxWXjJI zyEofzvF1X7++Lor6F4rpJ9pYiig5RALmSOhESYgGE9juT6SdyvkFQc8YOpSPJuZj6p34i CovNTAkmqBSy1c1Coi+gZrrzjjXC22IkvFmlwoRD2BZYV5c+l/NXzvUVj8vQjA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.21 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 66F5F10199 X-Spam-Score: -1.21 X-Migadu-Scanner: scn0.migadu.com X-TUID: w3TfKF8Lm2JH The call to delete_document can throw exceptions (and can happen in practice [1]), so catch the exception and extract the error message. As a side effect, also move the call to _n_m_has_term inside the try/catch. This should not change anything as that function already traps any Xapian exceptions. [1]: id:wwuk039sk2p.fsf@chaotikum.eu --- lib/message.cc | 22 +++++++++++----------- test/T566-lib-message.sh | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 1c87f8c0..5ccca95a 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1383,21 +1383,21 @@ _notmuch_message_delete (notmuch_message_t *message) if (status) return status; - message->notmuch->writable_xapian_db->delete_document (message->doc_id); - - /* if this was a ghost to begin with, we are done */ - private_status = _notmuch_message_has_term (message, "type", "ghost", &is_ghost); - if (private_status) - return COERCE_STATUS (private_status, - "Error trying to determine whether message was a ghost"); - if (is_ghost) - return NOTMUCH_STATUS_SUCCESS; - - /* look for a non-ghost message in the same thread */ try { Xapian::PostingIterator thread_doc, thread_doc_end; Xapian::PostingIterator mail_doc, mail_doc_end; + message->notmuch->writable_xapian_db->delete_document (message->doc_id); + + /* look for a non-ghost message in the same thread */ + /* if this was a ghost to begin with, we are done */ + private_status = _notmuch_message_has_term (message, "type", "ghost", &is_ghost); + if (private_status) + return COERCE_STATUS (private_status, + "Error trying to determine whether message was a ghost"); + if (is_ghost) + return NOTMUCH_STATUS_SUCCESS; + _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, &thread_doc, &thread_doc_end); _notmuch_database_find_doc_ids (message->notmuch, "type", "mail", &mail_doc, &mail_doc_end); diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh index 562ab05a..7f0e8eb0 100755 --- a/test/T566-lib-message.sh +++ b/test/T566-lib-message.sh @@ -518,7 +518,6 @@ test_expect_equal_file EXPECTED OUTPUT TERMLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/termlist.*) test_begin_subtest "remove message with corrupted db" -test_subtest_known_broken backup_database cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR} ${TERMLIST_PATH} { -- 2.35.2