]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Parser: Display token where parser fell down cf-err-show-line 23/head
authorPavel Tvrdik <pawel.tvrdik@gmail.com>
Fri, 11 Nov 2016 17:40:03 +0000 (18:40 +0100)
committerJan Maria Matejka <mq@ucw.cz>
Mon, 13 Aug 2018 12:10:00 +0000 (14:10 +0200)
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.

conf/conf.c
conf/conf.h
nest/cli.c
sysdep/unix/main.c

index 885e2e7e0ebf2b17ed85494d76239875cd729c0c..80bf6b8bddb735b50f06d533187255fb6eeaa0cc 100644 (file)
@@ -61,6 +61,8 @@ static jmp_buf conf_jmpbuf;
 
 struct config *config, *new_config;
 
+char *cf_text;                         /* Actual position from parser */
+
 static struct config *old_config;      /* Old configuration */
 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) */
@@ -511,6 +513,7 @@ cf_error(const char *msg, ...)
     strcpy(buf, "<bug: error message too long>");
   va_end(args);
   new_config->err_msg = cfg_strdup(buf);
+  new_config->err_token = cfg_strdup(cf_text);
   new_config->err_lino = ifs->lino;
   new_config->err_file_name = ifs->file_name;
   cf_lex_unwind();
index f174d352d22a62c490d13ca665ddc96acc84615d..ab94003398cfdc6642887d3be64ff305a47ebf7a 100644 (file)
@@ -49,6 +49,7 @@ struct config {
   int err_lino;                                /* Line containing error */
   char *err_file_name;                 /* File name containing error */
   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 */
   HASH(struct symbol) sym_hash;                /* Lexer: symbol hash table */
   struct config *fallback;             /* Link to regular config for CLI parsing */
index c421cc7e7c7e14b090a64927387b018b6a0067e7..148a626cf5b754eae39adba683756929a3bed989 100644 (file)
@@ -270,7 +270,7 @@ cli_command(struct cli *c)
   lp_flush(c->parser_pool);
   res = cli_parse(&f);
   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);
 }
index ea1476e7ad91f5ed9cd1175e8e02885498d02a49..dcfb9b4bb32baf6830970738c34d3f2f7813d0aa 100644 (file)
@@ -213,7 +213,7 @@ read_config(void)
   if (!unix_read_config(&conf, config_name))
     {
       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
        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 (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
        log(L_ERR "Unable to open configuration file %s: %m", config_name);
       config_free(conf);
@@ -251,7 +251,7 @@ cmd_read_config(char *name)
   if (!unix_read_config(&conf, name))
     {
       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
        cli_msg(8002, "%s: %m", name);
       config_free(conf);