From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id SCkAAs+4IWRhDwAASxT56A (envelope-from ) for ; Mon, 27 Mar 2023 17:39:59 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id GKauAc+4IWSAQgAAauVa8A (envelope-from ) for ; Mon, 27 Mar 2023 17:39:59 +0200 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 B1E64651F for ; Mon, 27 Mar 2023 17:39:58 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5DA525F3E5; Mon, 27 Mar 2023 15:39:51 +0000 (UTC) Received: from out-62.mta1.migadu.com (out-62.mta1.migadu.com [IPv6:2001:41d0:203:375::3e]) by mail.notmuchmail.org (Postfix) with ESMTPS id C7E785F36A for ; Mon, 27 Mar 2023 15:39:47 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=boula.in; s=key1; t=1679931587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3DVtg6IUdAJ0FP1y4Bultm3H8HPsd7Ge6U0YkIbI3Z4=; b=ZvNs2DWF9K5eWGJg3JxnqjN6mkbweySAtPhFl3HIU4npXGVeusxVOjF+SbTDmBHqEcVJUf JlBeYzirFvXHV90qWcr+NMZT2zt3oHRxr+AzYYJgEvD7aUPs2tT3imoMYKvGirNshrTF3L i4Y4p3QqaYit1YM4MSDRUab2alsTcJDJOAX12acPTClZJmFrz32cUiaqLN1BW6HdmMkIiQ QTK+ZgkWHwidPMCwYtkgG28tzNZ/Wg57yx/ZWkXfbS+Qj5ftY4PLw+uLBWa3LX3Avc2+bi 7if6rEepfwiWw7JBYCrbSvZVzmMRQOp6YZXztDe4ypy6Zf1wdSaaEjIGFDeM+w== From: Kevin Boulain To: notmuch@notmuchmail.org Subject: [PATCH v2 2/2] lib/message-property: catch xapian exceptions Date: Mon, 27 Mar 2023 17:39:43 +0200 Message-Id: <20230327153943.102856-2-kevin@boula.in> In-Reply-To: <87y1ni77ow.fsf@tethera.net> References: <87y1ni77ow.fsf@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WRZORGPIOKQVOFHDDGE45LWRX5452VJO X-Message-ID-Hash: WRZORGPIOKQVOFHDDGE45LWRX5452VJO X-MailFrom: kevin@boula.in X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0 CC: Kevin Boulain 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-Country: DE X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1679931598; a=rsa-sha256; cv=none; b=LFsFZxv2bVbSvYR9PxpsfLtJcUoS/JjSOdVZ11mXEiW2BjuHKumY5qbRf1wrNDqP3nOavS Eqx+YpM77N2lErOfkzciWseL+Noz7tSEgdVRzHSjY4p7bu+U49LWh+pDmT69OHs68r/Hll 4rFU9mq4PgAWkWDkvK4tNqMTSSOJa6EWpgatfbQlbe0YbhTqvGhri2VNYf+CLPmseAgwcl NIkDCl8Fk2RyWxx5OoYDEfWAKGKIcg1Pz5/d0KPmzrKd4yWuas5KA4msio1Bf9m+NMkHAl YIhbrt0Rc9VV7s+Ez14BIjIz06CJBzTCkpL3Zwyng75gK0xbdJAmT+MqrQgkVw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=boula.in header.s=key1 header.b=ZvNs2DWF; dmarc=fail reason="SPF not aligned (relaxed)" header.from=boula.in (policy=quarantine); 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1679931598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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:dkim-signature; bh=U2kXlio9InYqlfe9y8xF7ZLBxDEAk5TZ+4/Z6ELDhlw=; b=IbWHTo/zQuDOEfnEnCN09nel/8vtixM1Lt1FjNINnd30VLi0TPrV5i4hfd23qe1vzQVCJU OdF9flIofw7EVD9am42wNtJMvkstlfIDDYj8HtKDX2isyX9pmt9ikHEi+l8u27X1ZljyEN K0nfvr4ychl/lOE9fpZ5DXSH9QcfrCiGGQCWJ1fO+bwxCzgWizhk5Xaszp5jyCHqCsft5W VnWTgf7waymdZCSr3bj/KnRXcrXmkfI4hyYcYR/TUUPTRzJ7zFQ6utwwCxlxTQPgla6ewK p32+0tcqt1MW18n3Wopd1L/StzLgngO6XzAQPZ5JfEPzcXHGUBp8WTC2xPIikw== X-Migadu-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=boula.in header.s=key1 header.b=ZvNs2DWF; dmarc=fail reason="SPF not aligned (relaxed)" header.from=boula.in (policy=quarantine); 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: B1E64651F X-Spam: Yes X-Migadu-Spam-Score: 6.00 X-Spam-Score: 6.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: yMaU5ZUA4hvp Since libnotmuch exposes a C interface there's no way for clients to catch this. Inspired by what's done for tags (see notmuch_message_remove_tag). --- lib/message-property.cc | 36 +++++++++++++++++++++++++++++------ test/T610-message-property.sh | 2 -- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/message-property.cc b/lib/message-property.cc index d5afa30c..0d444bb8 100644 --- a/lib/message-property.cc +++ b/lib/message-property.cc @@ -25,6 +25,20 @@ #include "database-private.h" #include "message-private.h" +#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 at %s: %s\n", + where, + error.get_msg ().c_str ()); + notmuch->exception_reported = true; +} + notmuch_status_t notmuch_message_get_property (notmuch_message_t *message, const char *key, const char **value) { @@ -83,10 +97,15 @@ _notmuch_message_modify_property (notmuch_message_t *message, const char *key, c term = talloc_asprintf (message, "%s=%s", key, value); - if (delete_it) - private_status = _notmuch_message_remove_term (message, "property", term); - else - private_status = _notmuch_message_add_term (message, "property", term); + try { + if (delete_it) + private_status = _notmuch_message_remove_term (message, "property", term); + else + private_status = _notmuch_message_add_term (message, "property", term); + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } if (private_status) return COERCE_STATUS (private_status, @@ -130,8 +149,13 @@ _notmuch_message_remove_all_properties (notmuch_message_t *message, const char * else term_prefix = _find_prefix ("property"); - /* XXX better error reporting ? */ - _notmuch_message_remove_terms (message, term_prefix); + try { + /* XXX better error reporting ? */ + _notmuch_message_remove_terms (message, term_prefix); + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } return NOTMUCH_STATUS_SUCCESS; } diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh index 57ef018e..81112b05 100755 --- a/test/T610-message-property.sh +++ b/test/T610-message-property.sh @@ -363,7 +363,6 @@ EOF test_expect_equal_file /dev/null OUTPUT test_begin_subtest "edit property on removed message without uncaught exception" -test_subtest_known_broken cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} EXPECT0(notmuch_database_remove_message (db, notmuch_message_get_filename (message))); stat = notmuch_message_remove_property (message, "example", "example"); @@ -381,7 +380,6 @@ test_expect_equal_file EXPECTED OUTPUT add_email_corpus test_begin_subtest "remove all properties on removed message without uncaught exception" -test_subtest_known_broken cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} EXPECT0(notmuch_database_remove_message (db, notmuch_message_get_filename (message))); notmuch_message_remove_all_properties_with_prefix (message, "");