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