unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>,
	Maarten Aertsen <sagi-notmuch@rtsn.nl>,
	Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 3/3] cli/insert: return EX_TEMPFAIL for some errors
Date: Mon, 28 Nov 2016 18:12:31 -0400	[thread overview]
Message-ID: <20161128221231.25528-4-david@tethera.net> (raw)
In-Reply-To: <20161128221231.25528-1-david@tethera.net>

Attempt to distinguish between errors indicating misconfiguration or
programmer error, which we consider "permanent", in the sense that
automatic retries are unlikely to be useful, and those indicating
transient error conditions. We consider XAPIAN_EXCEPTION transient
because it covers the important special case of locking failure.
---
 notmuch-client.h    |  3 +++
 notmuch-insert.c    |  9 +++++----
 status.c            | 16 ++++++++++++++++
 test/T070-insert.sh | 36 ++++++++++++++++++++++++------------
 4 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 793f32e..d026e60 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -489,6 +489,9 @@ print_status_database (const char *loc,
 		       const notmuch_database_t *database,
 		       notmuch_status_t status);
 
+int
+status_to_exit (notmuch_status_t status);
+
 #include "command-line-arguments.h"
 
 extern char *notmuch_requested_db_uuid;
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 862da88..bc96af0 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -538,9 +538,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 	return EXIT_FAILURE;
     }
 
-   if (notmuch_database_open (notmuch_config_get_database_path (config),
-			       NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
-	return EXIT_FAILURE;
+    status = notmuch_database_open (notmuch_config_get_database_path (config),
+				    NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch);
+    if (status)
+	return keep ? NOTMUCH_STATUS_SUCCESS : status_to_exit (status);
 
     notmuch_exit_if_unmatched_db_uuid (notmuch);
 
@@ -577,5 +578,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 	notmuch_run_hook (db_path, "post-insert");
     }
 
-    return status ? EXIT_FAILURE : EXIT_SUCCESS;
+    return status_to_exit (status);
 }
diff --git a/status.c b/status.c
index 45d3fb4..8bc2fe4 100644
--- a/status.c
+++ b/status.c
@@ -36,3 +36,19 @@ print_status_database (const char *loc,
     }
     return status;
 }
+
+int
+status_to_exit (notmuch_status_t status)
+{
+    switch (status) {
+    case NOTMUCH_STATUS_SUCCESS:
+	return EXIT_SUCCESS;
+    case NOTMUCH_STATUS_OUT_OF_MEMORY:
+    case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
+    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
+    case NOTMUCH_STATUS_FILE_ERROR:
+	return EX_TEMPFAIL;
+    default:
+	return EXIT_FAILURE;
+    }
+}
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index 43b3abc..3e7d582 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -189,7 +189,6 @@ notmuch config set new.tags $OLDCONFIG
 
 for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \
     READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
-gen_insert_msg
 cat <<EOF > index-file-$code.gdb
 set breakpoint pending on
 set logging file index-file-$code.log
@@ -201,17 +200,30 @@ continue
 end
 run
 EOF
-test_begin_subtest "error exit when add_message returns $code"
-gdb --batch-silent --return-child-result \
-    -ex "set args insert < $gen_msg_filename" \
-    -x index-file-$code.gdb notmuch
-test_expect_equal $? 1
-
-test_begin_subtest "success exit with --keep when add_message returns $code"
-gdb --batch-silent --return-child-result \
-    -ex "set args insert --keep < $gen_msg_filename" \
-    -x index-file-$code.gdb notmuch
-test_expect_equal $? 0
+done
+
+gen_insert_msg
+
+for code in  FILE_NOT_EMAIL READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
+    test_expect_code 1 "EXIT_FAILURE when add_message returns $code" \
+         "gdb --batch-silent --return-child-result \
+	     -ex \"set args insert < $gen_msg_filename\" \
+	     -x index-file-$code.gdb notmuch"
+    test_expect_code 0 "success exit with --keep when add_message returns $code" \
+         "gdb --batch-silent --return-child-result \
+	     -ex \"set args insert --keep < $gen_msg_filename\" \
+	     -x index-file-$code.gdb notmuch"
+done
+
+for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
+    test_expect_code 75 "EX_TEMPFAIL when add_message returns $code" \
+         "gdb --batch-silent --return-child-result \
+	     -ex \"set args insert < $gen_msg_filename\" \
+	     -x index-file-$code.gdb notmuch"
+    test_expect_code 0 "success exit with --keep when add_message returns $code" \
+         "gdb --batch-silent --return-child-result \
+	     -ex \"set args insert --keep < $gen_msg_filename\" \
+	     -x index-file-$code.gdb notmuch"
 done
 
 test_done
-- 
2.10.2

  parent reply	other threads:[~2016-11-28 22:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-24 15:48 notmuch insert --keep fails in parallel w/ notmuch new Maarten Aertsen
2016-01-26 15:09 ` David Bremner
2016-02-07 21:13   ` [PATCH] cli: avoid non-zero exits in notmuch insert --keep Maarten Aertsen
2016-02-08 11:56     ` David Bremner
2016-11-28 12:16       ` [PATCH 1/2] cli/insert: delay database open until after writing mail file David Bremner
2016-11-28 12:16         ` [PATCH 2/2] cli/insert: return EX_TEMPFAIL for some errors David Bremner
2016-11-28 12:22           ` David Bremner
2016-11-28 22:12           ` v2 of insert tempfail series David Bremner
2016-11-28 22:12             ` [PATCH 1/3] test: gdb insert: redirect input inside gdb script David Bremner
2016-11-28 22:12             ` [PATCH 2/3] cli/insert: delay database open until after writing mail file David Bremner
2016-11-28 22:12             ` David Bremner [this message]
2016-12-04 20:51             ` v2 of insert tempfail series Tomi Ollila
2016-12-07 11:27               ` NEWS/docs for insert tempfail changes David Bremner
2016-12-07 11:27                 ` [PATCH 1/2] cli/insert: document the use of EX_TEMPFAIL David Bremner
2016-12-15 13:01                   ` David Bremner
2016-12-07 11:27                 ` [PATCH 2/2] NEWS: news for notmuch-insert error handling David Bremner
2016-12-10 19:26                 ` NEWS/docs for insert tempfail changes Tomi Ollila
2016-11-28 12:23         ` [PATCH 1/2] cli/insert: delay database open until after writing mail file David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161128221231.25528-4-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    --cc=sagi-notmuch@rtsn.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).