mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-21 14:17:30 -04:00
MINOR: cfgparse: try to suggest correct variable names on errors
When an empty argument comes from the use of a non-existing variable,
we'll now detect the difference with an empty variable (error pointer
points to the variable's name instead), and submit it to env_suggest()
to see if another variable looks likely to be the right one or not.
This can be quite useful to quickly figure how to fix misspelled variable
names. Currently only series of letters, digits and underscores are
attempted to be resolved as a name. A typical example is:
peer "${HAPROXY_LOCAL_PEER}" 127.0.0.1:10000
which produces:
[ALERT] (24231) : config : parsing [bug-argv4.cfg:2]: argument number 1 at position 13 is empty and marks the end of the argument list:
peer "${HAPROXY_LOCAL_PEER}" 127.0.0.1:10000
^
[NOTICE] (24231) : config : Hint: maybe you meant HAPROXY_LOCALPEER instead ?
This commit is contained in:
parent
49585049b9
commit
4c3351fd63
1 changed files with 19 additions and 0 deletions
|
|
@ -2074,6 +2074,7 @@ next_line:
|
|||
if (!*args[check_arg]) {
|
||||
static int warned_empty;
|
||||
size_t newpos;
|
||||
int suggest = 0;
|
||||
|
||||
/* if an empty arg was found, its pointer should be in <errptr>, except
|
||||
* for rare cases such as '\x00' etc. We need to check errptr in any case
|
||||
|
|
@ -2085,6 +2086,9 @@ next_line:
|
|||
if (newpos >= strlen(line))
|
||||
newpos = 0; // impossible to report anything, start at the beginning.
|
||||
errptr = line + newpos;
|
||||
} else if (isalnum((uchar)*errptr) || *errptr == '_') {
|
||||
/* looks like an environment variable */
|
||||
suggest = 1;
|
||||
}
|
||||
|
||||
/* sanitize input line in-place */
|
||||
|
|
@ -2096,6 +2100,21 @@ next_line:
|
|||
("Aborting to prevent all subsequent arguments from being silently ignored. "
|
||||
"If this is caused by an environment variable expansion, please have a look at section "
|
||||
"2.3 of the configuration manual to find solutions to address this.\n"));
|
||||
|
||||
if (suggest) {
|
||||
const char *end = errptr;
|
||||
struct ist alt;
|
||||
|
||||
while (isalnum((uchar)*end) || *end == '_')
|
||||
end++;
|
||||
|
||||
if (end > errptr) {
|
||||
alt = env_suggest(ist2(errptr, end - errptr));
|
||||
if (isttest(alt))
|
||||
ha_notice("Hint: maybe you meant %.*s instead ?\n", (int)istlen(alt), istptr(alt));
|
||||
}
|
||||
}
|
||||
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
fatal++;
|
||||
goto next_line;
|
||||
|
|
|
|||
Loading…
Reference in a new issue