From 3d39d346d793b9bea0c23ae2c16600feab11ee19 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 3 Sep 2014 11:28:34 -0400 Subject: cli: Be more helpful when .notmuch-config does not exist 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 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index db487dbe..a564bcae 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 { -- cgit v1.2.3