MINOR: http-rules: suggest approaching action names on mismatch
This adds support for action_suggest() in http-request, http-response
and http-after-response rulesets. For example:
parsing [/dev/stdin:2]: 'http-request' expects (...), but got 'del-hdr'. Did you mean 'del-header' maybe ?
diff --git a/src/http_rules.c b/src/http_rules.c
index 9271112..a34c560 100644
--- a/src/http_rules.c
+++ b/src/http_rules.c
@@ -76,7 +76,7 @@
struct act_rule *parse_http_req_cond(const char **args, const char *file, int linenum, struct proxy *proxy)
{
struct act_rule *rule;
- struct action_kw *custom = NULL;
+ const struct action_kw *custom = NULL;
int cur_arg;
rule = calloc(1, sizeof(*rule));
@@ -104,10 +104,15 @@
}
}
else {
+ const char *best = action_suggest(args[0], &http_req_keywords.list, NULL);
+
action_build_list(&http_req_keywords.list, &trash);
- ha_alert("parsing [%s:%d]: 'http-request' expects %s, but got '%s'%s.\n",
- file, linenum, trash.area,
- args[0], *args[0] ? "" : " (missing argument)");
+ ha_alert("parsing [%s:%d]: 'http-request' expects %s, but got '%s'%s.%s%s%s\n",
+ file, linenum, trash.area,
+ args[0], *args[0] ? "" : " (missing argument)",
+ best ? " Did you mean '" : "",
+ best ? best : "",
+ best ? "' maybe ?" : "");
goto out_err;
}
@@ -140,7 +145,7 @@
struct act_rule *parse_http_res_cond(const char **args, const char *file, int linenum, struct proxy *proxy)
{
struct act_rule *rule;
- struct action_kw *custom = NULL;
+ const struct action_kw *custom = NULL;
int cur_arg;
rule = calloc(1, sizeof(*rule));
@@ -168,10 +173,15 @@
}
}
else {
+ const char *best = action_suggest(args[0], &http_res_keywords.list, NULL);
+
action_build_list(&http_res_keywords.list, &trash);
- ha_alert("parsing [%s:%d]: 'http-response' expects %s, but got '%s'%s.\n",
- file, linenum, trash.area,
- args[0], *args[0] ? "" : " (missing argument)");
+ ha_alert("parsing [%s:%d]: 'http-response' expects %s, but got '%s'%s.%s%s%s\n",
+ file, linenum, trash.area,
+ args[0], *args[0] ? "" : " (missing argument)",
+ best ? " Did you mean '" : "",
+ best ? best : "",
+ best ? "' maybe ?" : "");
goto out_err;
}
@@ -205,7 +215,7 @@
struct act_rule *parse_http_after_res_cond(const char **args, const char *file, int linenum, struct proxy *proxy)
{
struct act_rule *rule;
- struct action_kw *custom = NULL;
+ const struct action_kw *custom = NULL;
int cur_arg;
rule = calloc(1, sizeof(*rule));
@@ -233,10 +243,15 @@
}
}
else {
+ const char *best = action_suggest(args[0], &http_after_res_keywords.list, NULL);
+
action_build_list(&http_after_res_keywords.list, &trash);
- ha_alert("parsing [%s:%d]: 'http-after-response' expects %s, but got '%s'%s.\n",
- file, linenum, trash.area,
- args[0], *args[0] ? "" : " (missing argument)");
+ ha_alert("parsing [%s:%d]: 'http-after-response' expects %s, but got '%s'%s.%s%s%s\n",
+ file, linenum, trash.area,
+ args[0], *args[0] ? "" : " (missing argument)",
+ best ? " Did you mean '" : "",
+ best ? best : "",
+ best ? "' maybe ?" : "");
goto out_err;
}