[PATCH 3/3] WIP: print error message from glib ini parser

Subject: [PATCH 3/3] WIP: print error message from glib ini parser

Date: Tue, 12 Sep 2023 21:56:36 -0300

To: notmuch@notmuchmail.org

Cc: eblake@redhat.com

From: David Bremner


---
 lib/config.cc | 7 ++++++-
 lib/open.cc   | 4 ++++
 notmuch.c     | 6 ++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/config.cc b/lib/config.cc
index 2323860d..11afb785 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -435,6 +435,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 +443,11 @@ _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) {
+		_notmuch_database_log (notmuch, "%s\n", gerr->message);
+		g_error_free (gerr);
+	    }
 	    if (! val) {
 		status = NOTMUCH_STATUS_FILE_ERROR;
 		goto DONE;
diff --git a/lib/open.cc b/lib/open.cc
index 54d1faf3..6dec7b07 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -556,6 +556,8 @@ _finish_open (notmuch_database_t *notmuch,
 
 	if (key_file)
 	    status = _notmuch_config_load_from_file (notmuch, key_file);
+	if (notmuch_database_status_string (notmuch))
+	    message = strdup( notmuch_database_status_string (notmuch));
 	if (status)
 	    goto DONE;
 
@@ -962,6 +964,8 @@ notmuch_database_load_config (const char *database_path,
 
     if (key_file) {
 	status = _notmuch_config_load_from_file (notmuch, key_file);
+	if (notmuch_database_status_string (notmuch))
+	    message = strdup( notmuch_database_status_string (notmuch));
 	if (status)
 	    goto DONE;
     }
diff --git a/notmuch.c b/notmuch.c
index 43554530..e790a44b 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)) {
-- 
2.40.1

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: