]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tcp-rules: suggest approaching action names on mismatch
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Mar 2021 12:46:10 +0000 (13:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Mar 2021 13:13:21 +0000 (14:13 +0100)
This adds support for action_suggest() in tcp-request and tcp-response
rules so as to propose the closest match in case of misspelling.

src/tcp_rules.c

index de99cff647a194274a456f0bb9960025df071c55..21a7c0fd86fc6910f0a38649e3e97fd2c9d8c7b7 100644 (file)
@@ -603,11 +603,17 @@ static int tcp_parse_response_rule(char **args, int arg, int section_type,
                        if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR)
                                return -1;
                } else {
+                       const char *extra[] = { "accept", "reject", "close", NULL };
+                       const char *best = action_suggest(args[arg], &tcp_res_cont_keywords, extra);
+
                        action_build_list(&tcp_res_cont_keywords, &trash);
                        memprintf(err,
-                                 "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s')",
+                                 "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s').%s%s%s",
                                  args[0], args[1], trash.area,
-                                 proxy_type_str(curpx), curpx->id, args[arg]);
+                                 proxy_type_str(curpx), curpx->id, args[arg],
+                                 best ? " Did you mean '" : "",
+                                 best ? best : "",
+                                 best ? "' maybe ?" : "");
                        return -1;
                }
        }
@@ -949,18 +955,32 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
                        if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR)
                                return -1;
                } else {
-                       if (where & SMP_VAL_FE_CON_ACC)
+                       const char *extra[] = { "accept", "reject", "capture", "track-sc", "expect-proxy", "expect-netscaler-ip", NULL };
+                       const char *best = NULL;
+
+
+                       if (where & SMP_VAL_FE_CON_ACC) {
                                action_build_list(&tcp_req_conn_keywords, &trash);
-                       else if (where & SMP_VAL_FE_SES_ACC)
+                               best = action_suggest(args[arg], &tcp_req_conn_keywords, extra);
+                       }
+                       else if (where & SMP_VAL_FE_SES_ACC) {
                                action_build_list(&tcp_req_sess_keywords, &trash);
-                       else
+                               best = action_suggest(args[arg], &tcp_req_sess_keywords, extra);
+                       }
+                       else {
                                action_build_list(&tcp_req_cont_keywords, &trash);
+                               best = action_suggest(args[arg], &tcp_req_cont_keywords, extra);
+                       }
+
                        memprintf(err,
                                  "'%s %s' expects 'accept', 'reject', 'capture', 'expect-proxy', 'expect-netscaler-ip', 'track-sc0' ... 'track-sc%d', %s "
-                                 "in %s '%s' (got '%s').\n",
+                                 "in %s '%s' (got '%s').%s%s%s\n",
                                  args[0], args[1], MAX_SESS_STKCTR-1,
                                  trash.area, proxy_type_str(curpx),
-                                 curpx->id, args[arg]);
+                                 curpx->id, args[arg],
+                                 best ? " Did you mean '" : "",
+                                 best ? best : "",
+                                 best ? "' maybe ?" : "");
                        return -1;
                }
        }