unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/4] Pass error message from GLib ini parser to CLI
Date: Fri, 15 Sep 2023 09:50:04 -0300	[thread overview]
Message-ID: <20230915125004.4129-5-david@tethera.net> (raw)
In-Reply-To: <20230915125004.4129-1-david@tethera.net>

The function _notmuch_config_load_from_file is only called in two
places in open.cc. Update internal API to match the idiom in open.cc.
Adding a newline is needed for consistency with other status strings.

Based in part on a patch [1] from Eric Blake.

[1]: id:20230906153402.101471-1-eblake@redhat.com
---
 lib/config.cc         | 13 +++++++++++--
 lib/notmuch-private.h |  2 +-
 lib/open.cc           |  4 ++--
 notmuch.c             |  6 ++++++
 test/T030-config.sh   |  1 -
 5 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/config.cc b/lib/config.cc
index 2323860d..6cd15fab 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -416,7 +416,8 @@ _expand_path (void *ctx, const char *key, const char *val)
 
 notmuch_status_t
 _notmuch_config_load_from_file (notmuch_database_t *notmuch,
-				GKeyFile *file)
+				GKeyFile *file,
+				char **status_string)
 {
     notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
     gchar **groups = NULL, **keys, *val;
@@ -435,6 +436,7 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
 	for (gchar **keys_p = keys; *keys_p; keys_p++) {
 	    char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp,  *keys_p);
 	    char *normalized_val;
+	    GError *gerr = NULL;
 
 	    /* If we opened from a given path, do not overwrite it */
 	    if (strcmp (absolute_key, "database.path") == 0 &&
@@ -442,7 +444,14 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
 		notmuch->xapian_db)
 		continue;
 
-	    val = g_key_file_get_string (file, *grp, *keys_p, NULL);
+	    val = g_key_file_get_string (file, *grp, *keys_p, &gerr);
+	    if (gerr) {
+		if (status_string)
+		    IGNORE_RESULT (asprintf (status_string,
+					     "GLib: %s\n",
+					     gerr->message));
+		g_error_free (gerr);
+	    }
 	    if (! val) {
 		status = NOTMUCH_STATUS_FILE_ERROR;
 		goto DONE;
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index c19ee8e2..367e23e6 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -726,7 +726,7 @@ notmuch_status_t
 _notmuch_config_load_from_database (notmuch_database_t *db);
 
 notmuch_status_t
-_notmuch_config_load_from_file (notmuch_database_t *db, GKeyFile *file);
+_notmuch_config_load_from_file (notmuch_database_t *db, GKeyFile *file, char **status_string);
 
 notmuch_status_t
 _notmuch_config_load_defaults (notmuch_database_t *db);
diff --git a/lib/open.cc b/lib/open.cc
index 54d1faf3..005872dc 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -555,7 +555,7 @@ _finish_open (notmuch_database_t *notmuch,
 	    goto DONE;
 
 	if (key_file)
-	    status = _notmuch_config_load_from_file (notmuch, key_file);
+	    status = _notmuch_config_load_from_file (notmuch, key_file, &message);
 	if (status)
 	    goto DONE;
 
@@ -961,7 +961,7 @@ notmuch_database_load_config (const char *database_path,
     }
 
     if (key_file) {
-	status = _notmuch_config_load_from_file (notmuch, key_file);
+	status = _notmuch_config_load_from_file (notmuch, key_file, &message);
 	if (status)
 	    goto DONE;
     }
diff --git a/notmuch.c b/notmuch.c
index 69a18131..814b9e42 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -563,6 +563,12 @@ main (int argc, char *argv[])
 					       NULL,
 					       &notmuch,
 					       &status_string);
+	if (status_string) {
+	    fputs (status_string, stderr);
+	    free (status_string);
+	    status_string = NULL;
+	}
+
 	switch (status) {
 	case NOTMUCH_STATUS_NO_CONFIG:
 	    if (! (command->mode & NOTMUCH_COMMAND_CONFIG_CREATE)) {
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 11428e8a..8aee9dc9 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -201,7 +201,6 @@ printf '[query]\nq3=from:\xff\n' >>bad-config
 test_expect_code 1 "notmuch --config=./bad-config config list"
 
 test_begin_subtest "Specific error message about bad utf8"
-test_subtest_known_broken
 notmuch --config=./bad-config config list 2>ERRORS
 cat <<EOF > EXPECTED
 GLib: Key file contains key “q3” with value “from:�” which is not UTF-8
-- 
2.40.1
\r

  parent reply	other threads:[~2023-09-15 12:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 12:50 Report GLib errors David Bremner
2023-09-15 12:50 ` [PATCH 1/4] test: add known broken test for bad utf8 in config David Bremner
2023-09-15 12:50 ` [PATCH 2/4] CLI: exit with error when load_config returns an error David Bremner
2023-09-15 12:50 ` [PATCH 3/4] test: add known broken subtest for the bad config error message David Bremner
2023-09-15 12:50 ` David Bremner [this message]
2023-09-23 11:47 ` Report GLib errors David Bremner

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=20230915125004.4129-5-david@tethera.net \
    --to=david@tethera.net \
    --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).