[PATCH] cli: Be more helpful when .notmuch-config does not exist
authorAustin Clements <amdragon@mit.edu>
Wed, 3 Sep 2014 15:28:34 +0000 (11:28 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:25 +0000 (10:04 -0800)
82/b96b71c1cc77ea84f794cfb04967c74e72d06b [new file with mode: 0644]

diff --git a/82/b96b71c1cc77ea84f794cfb04967c74e72d06b b/82/b96b71c1cc77ea84f794cfb04967c74e72d06b
new file mode 100644 (file)
index 0000000..8af9202
--- /dev/null
@@ -0,0 +1,145 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id ADC72431FB6\r
+       for <notmuch@notmuchmail.org>; Wed,  3 Sep 2014 08:28:49 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id tWwbPtRSaCHq for <notmuch@notmuchmail.org>;\r
+       Wed,  3 Sep 2014 08:28:45 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu\r
+       [18.7.68.36])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 3B77F431FAF\r
+       for <notmuch@notmuchmail.org>; Wed,  3 Sep 2014 08:28:45 -0700 (PDT)\r
+X-AuditID: 12074424-f79346d000004923-0d-540733aac398\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id E3.4C.18723.AA337045; Wed,  3 Sep 2014 11:28:42 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s83FSeG5022321; \r
+       Wed, 3 Sep 2014 11:28:41 -0400\r
+Received: from drake.dyndns.org\r
+       (static-155-212-141-65.mas.onecommunications.net [155.212.141.65])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s83FSb0F031023\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Wed, 3 Sep 2014 11:28:40 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XPCU8-0006Lk-67; Wed, 03 Sep 2014 11:28:36 -0400\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] cli: Be more helpful when .notmuch-config does not exist\r
+Date: Wed,  3 Sep 2014 11:28:34 -0400\r
+Message-Id: <1409758114-24361-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.1.0\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrKIsWRmVeSWpSXmKPExsUixG6nrrvKmD3EYOd7C4vrN2cyOzB6PFt1\r
+       izmAMYrLJiU1J7MstUjfLoErY+H16WwFV4UqTnavYmpgfM7XxcjJISFgIrH5yUFGCFtM4sK9\r
+       9WxdjFwcQgKzmSRWfPvHCuFsYJQ4uuscI4RznUni/97TUM5cRok930HKODnYBDQkft9azARi\r
+       iwhIS+y8OxsozsHBLKAm8adLBcQUFvCUWP9UEcRkEVCV6J3gA1LMK+Ag8X3uJTaII+QkNuz+\r
+       zziBkXcBI8MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXXO93MwSvdSU0k2M4BBwUdnB2HxI6RCj\r
+       AAejEg+vhx9biBBrYllxZe4hRkkOJiVR3jkG7CFCfEn5KZUZicUZ8UWlOanFhxglOJiVRHjX\r
+       SAPleFMSK6tSi/JhUtIcLErivG+trYKFBNITS1KzU1MLUotgsjIcHEoSvC8NgRoFi1LTUyvS\r
+       MnNKENJMHJwgw3mAhmsYgQwvLkjMLc5Mh8ifYtTlWNf5rZ9JiCUvPy9VSpz3C8ggAZCijNI8\r
+       uDmw2H3FKA70ljCvJsgoHmDcw016BbSECWiJWw4ryJKSRISUVAOjDE/41B2H/l96YFGWfYf/\r
+       wIH5U+o61X3Mz/l/qhNqTuryniPlpVazS1r0n4VvdJLG8W13Hi/YsPBvthCXF0f07y/qN3ZO\r
+       Y3XWZ72av3zKjSmLhdPPrpcuNup0KOlvffm5Vrr9rMfJS5s0PzxaMSlQXXi6i4ayWl56SOtb\r
+       gf6Vz3rDY52K/TKUWIozEg21mIuKEwESaxpUuAIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 03 Sep 2014 15:28:49 -0000\r
+\r
+Previously, if the user ran any subcommand that required a\r
+configuration (e.g., notmuch new) but didn't have a configuration,\r
+notmuch would give the rather un-friendly and un-actionable message\r
+\r
+  Error reading configuration file .notmuch-config: No such file or directory\r
+\r
+Since this condition is expected for new users, this patch adds\r
+specific handling for the file-not-found case to give a message that\r
+is friendly and actionable.\r
+---\r
+ notmuch-config.c   | 26 ++++++++++++++++----------\r
+ test/T040-setup.sh |  6 ++++++\r
+ 2 files changed, 22 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index db487db..a564bca 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -283,16 +283,22 @@ notmuch_config_open (void *ctx,\r
+                                    G_KEY_FILE_KEEP_COMMENTS,\r
+                                    &error))\r
+     {\r
+-      /* If create_new is true, then the caller is prepared for a\r
+-       * default configuration file in the case of FILE NOT\r
+-       * FOUND. Otherwise, any read failure is an error.\r
+-       */\r
+-      if (create_new &&\r
+-          error->domain == G_FILE_ERROR &&\r
+-          error->code == G_FILE_ERROR_NOENT)\r
+-      {\r
+-          g_error_free (error);\r
+-          config->is_new = TRUE;\r
++      if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT) {\r
++          /* If create_new is true, then the caller is prepared for a\r
++           * default configuration file in the case of FILE NOT\r
++           * FOUND.\r
++           */\r
++          if (create_new) {\r
++              g_error_free (error);\r
++              config->is_new = TRUE;\r
++          } else {\r
++              fprintf (stderr, "Configuration file %s not found.\n"\r
++                       "Try running 'notmuch setup' to create a configuration.\n",\r
++                       config->filename);\r
++              talloc_free (config);\r
++              g_error_free (error);\r
++              return NULL;\r
++          }\r
+       }\r
+       else\r
+       {\r
+diff --git a/test/T040-setup.sh b/test/T040-setup.sh\r
+index 124ef1c..b1972e7 100755\r
+--- a/test/T040-setup.sh\r
++++ b/test/T040-setup.sh\r
+@@ -3,6 +3,12 @@\r
+ test_description='"notmuch setup"'\r
+ . ./test-lib.sh\r
\r
++test_begin_subtest "Notmuch new without a config suggests notmuch setup"\r
++output=$(notmuch --config=new-notmuch-config new 2>&1)\r
++test_expect_equal "$output" "\\r
++Configuration file new-notmuch-config not found.\r
++Try running 'notmuch setup' to create a configuration."\r
++\r
+ test_begin_subtest "Create a new config interactively"\r
+ notmuch --config=new-notmuch-config > /dev/null <<EOF\r
+ Test Suite\r
+-- \r
+2.1.0\r
+\r