]> git.notmuchmail.org Git - notmuch/commitdiff
Pass error message from GLib ini parser to CLI
authorDavid Bremner <david@tethera.net>
Fri, 15 Sep 2023 12:50:04 +0000 (09:50 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 23 Sep 2023 11:34:48 +0000 (08:34 -0300)
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
lib/notmuch-private.h
lib/open.cc
notmuch.c
test/T030-config.sh

index 2323860dbc3ba7a999c698944b22fe43ad28e376..6cd15fab26bc16610e1c56e1b5e0019b41279259 100644 (file)
@@ -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;
index c19ee8e20a4b0c6785481509b921639a563c703f..367e23e610d0220df108eed1cc078694b10bfea9 100644 (file)
@@ -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);
index 54d1faf30127c8a72f3c96e838cf9d4edba7e70a..005872dc2c5877d5f0ac483b0ef2cec19b2ca85c 100644 (file)
@@ -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;
     }
index 69a181319315261408a93d0d44935fe2084ac374..814b9e42a59f46ae675f24f688005ec22ab58914 100644 (file)
--- 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)) {
index 636b5a53f48469262b9e3fc79b28bdca8f6ffb1e..621e0b69721091a5f7383db7db726004fadc2c4f 100755 (executable)
@@ -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