mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Parser: Display token where parser fell down
For example I misspelled device protocol bird: bird.conf, line 11 (nearby 'demice'): syntax error It would be better to display whole err line. We can read it from config->err_file_name again and display the line at config->err_lino.
This commit is contained in:
parent
179e2a0934
commit
4d62bdd636
@ -61,6 +61,8 @@ static jmp_buf conf_jmpbuf;
|
|||||||
|
|
||||||
struct config *config, *new_config;
|
struct config *config, *new_config;
|
||||||
|
|
||||||
|
char *cf_text; /* Actual position from parser */
|
||||||
|
|
||||||
static struct config *old_config; /* Old configuration */
|
static struct config *old_config; /* Old configuration */
|
||||||
static struct config *future_config; /* New config held here if recon requested during recon */
|
static struct config *future_config; /* New config held here if recon requested during recon */
|
||||||
static int old_cftype; /* Type of transition old_config -> config (RECONFIG_SOFT/HARD) */
|
static int old_cftype; /* Type of transition old_config -> config (RECONFIG_SOFT/HARD) */
|
||||||
@ -511,6 +513,7 @@ cf_error(const char *msg, ...)
|
|||||||
strcpy(buf, "<bug: error message too long>");
|
strcpy(buf, "<bug: error message too long>");
|
||||||
va_end(args);
|
va_end(args);
|
||||||
new_config->err_msg = cfg_strdup(buf);
|
new_config->err_msg = cfg_strdup(buf);
|
||||||
|
new_config->err_token = cfg_strdup(cf_text);
|
||||||
new_config->err_lino = ifs->lino;
|
new_config->err_lino = ifs->lino;
|
||||||
new_config->err_file_name = ifs->file_name;
|
new_config->err_file_name = ifs->file_name;
|
||||||
cf_lex_unwind();
|
cf_lex_unwind();
|
||||||
|
@ -49,6 +49,7 @@ struct config {
|
|||||||
int err_lino; /* Line containing error */
|
int err_lino; /* Line containing error */
|
||||||
char *err_file_name; /* File name containing error */
|
char *err_file_name; /* File name containing error */
|
||||||
char *file_name; /* Name of main configuration file */
|
char *file_name; /* Name of main configuration file */
|
||||||
|
char *err_token; /* Token where parser fell down */
|
||||||
int file_fd; /* File descriptor of main configuration file */
|
int file_fd; /* File descriptor of main configuration file */
|
||||||
HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */
|
HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */
|
||||||
struct config *fallback; /* Link to regular config for CLI parsing */
|
struct config *fallback; /* Link to regular config for CLI parsing */
|
||||||
|
@ -270,7 +270,7 @@ cli_command(struct cli *c)
|
|||||||
lp_flush(c->parser_pool);
|
lp_flush(c->parser_pool);
|
||||||
res = cli_parse(&f);
|
res = cli_parse(&f);
|
||||||
if (!res)
|
if (!res)
|
||||||
cli_printf(c, 9001, f.err_msg);
|
cli_printf(c, 9001, "Bad command (nearby '%s'): %s", f.err_token, f.err_msg);
|
||||||
|
|
||||||
config_free(&f);
|
config_free(&f);
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ read_config(void)
|
|||||||
if (!unix_read_config(&conf, config_name))
|
if (!unix_read_config(&conf, config_name))
|
||||||
{
|
{
|
||||||
if (conf->err_msg)
|
if (conf->err_msg)
|
||||||
die("%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
|
die("%s, line %d (nearby '%s'): %s", conf->err_file_name, conf->err_lino, conf->err_token, conf->err_msg);
|
||||||
else
|
else
|
||||||
die("Unable to open configuration file %s: %m", config_name);
|
die("Unable to open configuration file %s: %m", config_name);
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ async_config(void)
|
|||||||
if (!unix_read_config(&conf, config_name))
|
if (!unix_read_config(&conf, config_name))
|
||||||
{
|
{
|
||||||
if (conf->err_msg)
|
if (conf->err_msg)
|
||||||
log(L_ERR "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
|
log(L_ERR "%s, line %d (nearby '%s'): %s", conf->err_file_name, conf->err_lino, conf->err_token, conf->err_msg);
|
||||||
else
|
else
|
||||||
log(L_ERR "Unable to open configuration file %s: %m", config_name);
|
log(L_ERR "Unable to open configuration file %s: %m", config_name);
|
||||||
config_free(conf);
|
config_free(conf);
|
||||||
@ -251,7 +251,7 @@ cmd_read_config(char *name)
|
|||||||
if (!unix_read_config(&conf, name))
|
if (!unix_read_config(&conf, name))
|
||||||
{
|
{
|
||||||
if (conf->err_msg)
|
if (conf->err_msg)
|
||||||
cli_msg(8002, "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
|
cli_msg(8002, "%s, line %d (nearby '%s'): %s", conf->err_file_name, conf->err_lino, conf->err_token, conf->err_msg);
|
||||||
else
|
else
|
||||||
cli_msg(8002, "%s: %m", name);
|
cli_msg(8002, "%s: %m", name);
|
||||||
config_free(conf);
|
config_free(conf);
|
||||||
|
Loading…
Reference in New Issue
Block a user