]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: improve parsing error for server-template
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 29 Jul 2026 08:39:54 +0000 (10:39 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 29 Jul 2026 09:39:30 +0000 (11:39 +0200)
When parsing a server configuration line, a global context is set to the
current server instance. This allows to automatically prefix any
warning/error messages by the server name. This prefix is generated via
generate_usermsgs_ctx_str().

The output was not useful for server-template lines as server <id> is
NULL for them. Thus, this patch improves generate_usermsgs_ctx_str() to
identify a server-template. Now, a dedicated 'server-template' prefix is
generated, with <tmpl_info.prefix> used instead of NULL <id> field.

* Example of a previous error message :
[ALERT]    (39934) : config : [./hap.cfg:54] : 'server-template be/(null)' : error detected while parsing [...]
* Example of a new error message :
[ALERT]    (40205) : config : [./hap.cfg:54] : 'server-template be/local' : error detected while parsing [...]

src/errors.c

index 9f334dbe4af239d18121a072028ffc89f91b4b1f..229218e32a0642ff25d704e96e0043e441cfec1c 100644 (file)
@@ -193,6 +193,8 @@ void reset_usermsgs_ctx(void)
 static void generate_usermsgs_ctx_str(void)
 {
        struct usermsgs_ctx *ctx = &usermsgs_ctx;
+       struct server *srv;
+       const char *srv_id;
        void *area;
        int ret;
 
@@ -219,10 +221,12 @@ static void generate_usermsgs_ctx_str(void)
 
                switch (obj_type(ctx->obj)) {
                case OBJ_TYPE_SERVER:
+                       srv = __objt_server(ctx->obj);
+                       srv_id = srv->id ? srv->id : srv->tmpl_info.prefix;
                        ret = snprintf(b_tail(&ctx->str), b_room(&ctx->str),
-                                      "'server %s/%s' : ",
-                                      __objt_server(ctx->obj)->proxy->id,
-                                      __objt_server(ctx->obj)->id);
+                                      "'%s %s/%s' : ",
+                                      srv->id ? "server" : "server-template",
+                                      srv->proxy->id, srv_id);
                        b_add(&ctx->str, MIN(ret, b_room(&ctx->str)));
                        break;