]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: When showing an "Unknown setting" error, show the full section path
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 20 May 2017 15:13:45 +0000 (18:13 +0300)
committerGitLab <gitlab@git.dovecot.net>
Sat, 20 May 2017 18:23:51 +0000 (21:23 +0300)
For example with:

service foo {
  inet_listener bar {
    key = value
  }
}

Instead of showing just:

Unknown setting: key

Show the entire path:

Unknown setting: service { inet_listener { key

Any filters won't be shown, because they don't affect the result.

src/config/config-parser-private.h
src/config/config-parser.c

index 2527c5f9d44a2d7fcf455802f72f5808d9a6f7a1..9fe98cee54c594af97c666bb4576f7188e1abbae 100644 (file)
@@ -19,6 +19,7 @@ enum config_line_type {
 
 struct config_section_stack {
        struct config_section_stack *prev;
+       const char *key;
 
        struct config_filter filter;
        /* root=NULL-terminated list of parsers */
@@ -27,6 +28,7 @@ struct config_section_stack {
 
        const char *open_path;
        unsigned int open_linenum;
+       bool is_filter;
 };
 
 struct input_stack {
index b8578f4785bb4a096b6e3bb2eeb8b06fa42cd77f..be0f6c7d6e4d20204bb51d9598314d3949fedcf1 100644 (file)
@@ -99,6 +99,27 @@ config_parser_is_in_localremote(struct config_section_stack *section)
                filter->remote_bits > 0;
 }
 
+static void
+section_stack_write(string_t *str, struct config_section_stack *section)
+{
+       if (section == NULL)
+               return;
+
+       section_stack_write(str, section->prev);
+       if (!section->is_filter && section->key != NULL)
+               str_printfa(str, "%s { ", section->key);
+}
+
+static const char *
+get_setting_full_path(struct config_parser_context *ctx, const char *key)
+{
+       string_t *str = t_str_new(128);
+
+       section_stack_write(str, ctx->cur_section);
+       str_append(str, key);
+       return str_c(str);
+}
+
 int config_apply_line(struct config_parser_context *ctx, const char *key,
                      const char *line, const char *section_name)
 {
@@ -131,7 +152,7 @@ int config_apply_line(struct config_parser_context *ctx, const char *key,
        }
        if (!found) {
                ctx->error = p_strconcat(ctx->pool, "Unknown setting: ",
-                                        key, NULL);
+                                        get_setting_full_path(ctx, key), NULL);
                return -1;
        }
        return 0;
@@ -332,6 +353,7 @@ config_filter_add_new_filter(struct config_parser_context *ctx,
                ctx->cur_section->parsers = parser->parsers;
        else
                config_add_new_parser(ctx);
+       ctx->cur_section->is_filter = TRUE;
        return TRUE;
 }
 
@@ -899,6 +921,7 @@ void config_parser_apply_line(struct config_parser_context *ctx,
        case CONFIG_LINE_TYPE_SECTION_BEGIN:
                ctx->cur_section = config_add_new_section(ctx);
                ctx->cur_section->pathlen = ctx->pathlen;
+               ctx->cur_section->key = p_strdup(ctx->pool, key);
 
                if (config_filter_add_new_filter(ctx, key, value)) {
                        /* new filter */