unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Peter Wang <novalazy@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 07/10] cli: indicate insert failure mode in exit status
Date: Wed, 16 Apr 2014 22:59:22 +1000	[thread overview]
Message-ID: <1397653165-15620-8-git-send-email-novalazy@gmail.com> (raw)
In-Reply-To: <1397653165-15620-1-git-send-email-novalazy@gmail.com>

Make insert return a different exit code, 2, for failure to write the
message file to disk, and exit code 1 for other errors.
---
 notmuch-insert.c    | 30 ++++++++++++++++++------------
 test/T070-insert.sh |  4 ++--
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index 7db4f73..29d82c9 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -28,6 +28,12 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+enum {
+    INSERT_EXIT_SUCCESS = 0,
+    INSERT_EXIT_FAILURE = 1,
+    INSERT_EXIT_FAILED_WRITE = 2
+};
+
 static volatile sig_atomic_t interrupted;
 
 static void
@@ -408,7 +414,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 
     opt_index = parse_arguments (argc, argv, options, 1);
     if (opt_index < 0)
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILURE;
 
     db_path = notmuch_config_get_database_path (config);
     new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
@@ -417,7 +423,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     tag_ops = tag_op_list_create (config);
     if (tag_ops == NULL) {
 	fprintf (stderr, "Out of memory.\n");
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILURE;
     }
     for (i = 0; i < new_tags_length; i++) {
 	const char *error_msg;
@@ -426,20 +432,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 	if (error_msg) {
 	    fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",
 		     new_tags[i],  error_msg);
-	    return EXIT_FAILURE;
+	    return INSERT_EXIT_FAILURE;
 	}
 
 	if (tag_op_list_append (tag_ops, new_tags[i], FALSE))
-	    return EXIT_FAILURE;
+	    return INSERT_EXIT_FAILURE;
     }
 
     if (parse_tag_command_line (config, argc - opt_index, argv + opt_index,
 				&query_string, tag_ops))
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILURE;
 
     if (*query_string != '\0') {
 	fprintf (stderr, "Error: unexpected query string: %s\n", query_string);
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILURE;
     }
 
     if (folder == NULL) {
@@ -447,17 +453,17 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     } else {
 	if (! check_folder_name (folder)) {
 	    fprintf (stderr, "Error: bad folder name: %s\n", folder);
-	    return EXIT_FAILURE;
+	    return INSERT_EXIT_FAILURE;
 	}
 	maildir = talloc_asprintf (config, "%s/%s", db_path, folder);
 	if (! maildir) {
 	    fprintf (stderr, "Out of memory\n");
-	    return EXIT_FAILURE;
+	    return INSERT_EXIT_FAILURE;
 	}
 	if (create_folder && ! maildir_create_folder (config, maildir)) {
 	    fprintf (stderr, "Error: creating maildir %s: %s\n",
 		     maildir, strerror (errno));
-	    return EXIT_FAILURE;
+	    return INSERT_EXIT_FAILURE;
 	}
     }
 
@@ -471,12 +477,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 
     if (notmuch_database_open (notmuch_config_get_database_path (config),
 			       NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILURE;
 
     /* Write the message to the Maildir new directory. */
     if (! write_message (config, STDIN_FILENO, maildir, &newpath)) {
 	notmuch_database_destroy (notmuch);
-	return EXIT_FAILURE;
+	return INSERT_EXIT_FAILED_WRITE;
     }
 
     /* Add the message to the index.
@@ -486,5 +492,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 				    synchronize_flags);
 
     notmuch_database_destroy (notmuch);
-    return EXIT_SUCCESS;
+    return INSERT_EXIT_SUCCESS;
 }
diff --git a/test/T070-insert.sh b/test/T070-insert.sh
index ea9db07..c576efc 100755
--- a/test/T070-insert.sh
+++ b/test/T070-insert.sh
@@ -18,7 +18,7 @@ gen_insert_msg() {
 	"[body]=\"insert-message\""
 }
 
-test_expect_code 1 "Insert zero-length file" \
+test_expect_code 2 "Insert zero-length file" \
     "notmuch insert < /dev/null"
 
 # This test is a proxy for other errors that may occur while trying to
@@ -137,7 +137,7 @@ output=$(notmuch search --output=messages path:Drafts/cur tag:draft NOT tag:unre
 test_expect_equal "$output" "id:$gen_msg_id"
 
 gen_insert_msg
-test_expect_code 1 "Insert message into non-existent folder" \
+test_expect_code 2 "Insert message into non-existent folder" \
     "notmuch insert --folder=nonesuch < $gen_msg_filename"
 
 test_begin_subtest "Insert message, create folder"
-- 
1.8.4

  parent reply	other threads:[~2014-04-16 13:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-16 12:59 [PATCH v2 00/10] add insert --must-index option Peter Wang
2014-04-16 12:59 ` [PATCH v2 01/10] lib: add return status to database close and destroy Peter Wang
2014-07-05 12:39   ` David Bremner
2014-07-09 23:41   ` David Bremner
2014-04-16 12:59 ` [PATCH v2 02/10] lib: bump soname Peter Wang
2014-04-16 12:59 ` [PATCH v2 03/10] python: handle return status of database close and destroy Peter Wang
2014-07-05 12:43   ` David Bremner
2014-04-16 12:59 ` [PATCH v2 04/10] go: add return status to database close method Peter Wang
2014-04-16 12:59 ` [PATCH v2 05/10] ruby: handle return status of database close Peter Wang
2014-07-05 12:55   ` David Bremner
2014-04-16 12:59 ` [PATCH v2 06/10] cli: refactor insert Peter Wang
2014-07-05 13:18   ` David Bremner
2014-07-06  3:57     ` Peter Wang
2014-07-08 23:24       ` David Bremner
2014-09-16 19:32       ` David Bremner
2014-04-16 12:59 ` Peter Wang [this message]
2014-04-16 12:59 ` [PATCH v2 08/10] cli: add insert --must-index option Peter Wang
2014-07-09 23:20   ` David Bremner
2014-07-28 14:48     ` Peter Wang
2014-04-16 12:59 ` [PATCH v2 09/10] test: test insert --must-index Peter Wang
2014-04-16 12:59 ` [PATCH v2 10/10] man: update insert documentation Peter Wang
2014-05-06 21:00 ` [PATCH v2 00/10] add insert --must-index option Tomi Ollila

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=1397653165-15620-8-git-send-email-novalazy@gmail.com \
    --to=novalazy@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /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).