]> git.notmuchmail.org Git - notmuch/commitdiff
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 -0400)
committerDavid Bremner <david@tethera.net>
Sun, 7 Sep 2014 18:01:01 +0000 (20:01 +0200)
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
test/T040-setup.sh

index db487dbe828ba808b6c3223a8d33df581864d74f..a564bcae362f6b0b9304ade15e580faa67f84437 100644 (file)
@@ -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
        {
index 124ef1c8e04b94959453b0630d7f9e320e1c1507..b1972e70c3b151e897275d303abc2f7bedfbe56d 100755 (executable)
@@ -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 <<EOF
 Test Suite