mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-24 12:20:59 +01:00
MEDIUM: pattern: report the precise argument parsing error when known.
The argument parser knows what exact error it has faced, and the pattern parser is able to report errors, so let's make use of it. From now on, it becomes possible to detect such things : $ ./haproxy -db -f echo5.cfg [ALERT] 110/160344 (4791) : parsing [echo5.cfg:38] : 'stick': invalid arg 2 in fetch method 'payload' : Missing arguments (got 1/2), type 'unsigned integer' expected. [ALERT] 110/160344 (4791) : parsing [echo5.cfg:39] : 'stick': invalid args in fetch method 'payload' : payload length must be > 0. [ALERT] 110/160344 (4791) : parsing [echo5.cfg:40] : 'stick': invalid arg 3 in fetch method 'payload_lv' : Failed to parse 'x' as type 'signed integer'. [ALERT] 110/160344 (4791) : parsing [echo5.cfg:41] : 'stick': invalid arg 4 in fetch method 'payload_lv' : End of arguments expected at ',13'. [ALERT] 110/160344 (4791) : Error(s) found in configuration file : echo5.cfg [ALERT] 110/160344 (4791) : Fatal errors found in configuration.
This commit is contained in:
parent
21d68a6895
commit
b27c0d35dd
@ -316,7 +316,8 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
|
||||
expr->fetch = fetch;
|
||||
|
||||
if (end != endw) {
|
||||
char *err_msg;
|
||||
char *err_msg = NULL;
|
||||
int err_arg;
|
||||
|
||||
if (!fetch->arg_mask) {
|
||||
p = my_strndup(str[*idx], endw - str[*idx]);
|
||||
@ -327,12 +328,13 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (make_arg_list(endw + 1, end - endw - 2, fetch->arg_mask, &expr->arg_p, NULL, NULL, NULL) < 0) {
|
||||
if (make_arg_list(endw + 1, end - endw - 2, fetch->arg_mask, &expr->arg_p, &err_msg, NULL, &err_arg) < 0) {
|
||||
p = my_strndup(str[*idx], endw - str[*idx]);
|
||||
if (p) {
|
||||
snprintf(err, err_size, "invalid args in fetch method '%s'.", p);
|
||||
snprintf(err, err_size, "invalid arg %d in fetch method '%s' : %s.", err_arg+1, p, err_msg);
|
||||
free(p);
|
||||
}
|
||||
free(err_msg);
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
@ -405,7 +407,8 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
|
||||
conv_expr->conv = conv;
|
||||
|
||||
if (end != endw) {
|
||||
char *err_msg;
|
||||
char *err_msg = NULL;
|
||||
int err_arg;
|
||||
|
||||
if (!conv->arg_mask) {
|
||||
p = my_strndup(str[*idx], endw - str[*idx]);
|
||||
@ -417,12 +420,13 @@ struct pattern_expr *pattern_parse_expr(char **str, int *idx, char *err, int err
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (make_arg_list(endw + 1, end - endw - 2, conv->arg_mask, &conv_expr->arg_p, NULL, NULL, NULL) < 0) {
|
||||
if (make_arg_list(endw + 1, end - endw - 2, conv->arg_mask, &conv_expr->arg_p, &err_msg, NULL, &err_arg) < 0) {
|
||||
p = my_strndup(str[*idx], endw - str[*idx]);
|
||||
if (p) {
|
||||
snprintf(err, err_size, "invalid args in conv method '%s'.", p);
|
||||
snprintf(err, err_size, "invalid arg %d in conv method '%s' : %s.", err_arg+1, p, err_msg);
|
||||
free(p);
|
||||
}
|
||||
free(err_msg);
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user