Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfg: wrong position is printed in log messages in case of parser error #65

Closed
vdmit11 opened this issue Feb 27, 2015 · 2 comments
Closed
Assignees
Milestone

Comments

@vdmit11
Copy link
Contributor

vdmit11 commented Feb 27, 2015

Scenario:

  1. Take the default configuration file that consists of comments only.
  2. Type few random characters (e.g. sdafasdg) in the middle of the file.
  3. Start Tempesta FW.

Something like this appears in the log:

[   10.728074] [tempesta] ERROR: syntax error
[   10.728561] [tempesta] ERROR: configuration parsing error:
[   10.728561] 
[   10.728561] #   cache_size 1048576; # 1 GiB
[   10.728561] #
[   10.728561] # Default:
[   10.728561] #   cache_size 262144;  # 256 MiB
[   10.728561] 
[   10.728561] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It shows the wrong position in the configuration file.
That happens because the parser tries to read more tokens and eventually reaches EOF without meeting a ; character which is a syntax error.
The position where the parser stops is the end of the buffer, so it shows some contents around this position which is not what you expect to see.

Generally this is not about EOF, the tokenizer always eats comments implicitly, so you always see a wrong position in the log message if there are comments after it.
The default configuration file contains a lot of comments, so this is an issue.

TODO:

  1. Try to display an actual position where an error happens. Perhaps need to show position of the previous token, not the current one. Or a position where the current entry started, but where the parser terminated.
  2. Add more info: show file/line and expected/got clauses.
@vdmit11 vdmit11 added the bug label Feb 27, 2015
@vdmit11 vdmit11 changed the title wrong position is shown for configuration parsing error messages cfg: wrong position is printed in log messages in case of parser error Mar 1, 2015
@krizhanovsky krizhanovsky modified the milestones: 0.4.0 Web Server, 0.5.0 SSL, Stable Mar 10, 2015
@krizhanovsky krizhanovsky modified the milestones: 0.6.0 Stable, 0.5.0 SSL & TDB Jun 19, 2015
@krizhanovsky krizhanovsky modified the milestones: 0.5.0 Web Server, 0.6.0 Stable Aug 24, 2015
@sergsever
Copy link
Contributor

Tryed now. Inserted random string in the middle config file, then started tempesta, in log was text:
[tempesta] ERROR: configuration parsing error:
Oct 26 14:55:57 localhost kernel: [tempesta] ERROR: can't parse configuration data
Oct 26 14:55:57 localhost kernel: [tempesta] ERROR: failed to start modules
all on master.

sergsever pushed a commit that referenced this issue Mar 22, 2016
sergsever pushed a commit that referenced this issue Mar 30, 2016
sergsever pushed a commit that referenced this issue Mar 30, 2016
sergsever pushed a commit that referenced this issue Mar 30, 2016
sergsever pushed a commit that referenced this issue May 6, 2016
sergsever pushed a commit that referenced this issue May 6, 2016
sergsever pushed a commit that referenced this issue May 6, 2016
sergsever pushed a commit that referenced this issue May 30, 2016
sergsever pushed a commit that referenced this issue May 30, 2016
sergsever pushed a commit that referenced this issue May 30, 2016
sergsever pushed a commit that referenced this issue May 30, 2016
@krizhanovsky krizhanovsky assigned vankoven and unassigned sergsever Jan 29, 2017
@krizhanovsky
Copy link
Contributor

krizhanovsky commented Jan 29, 2017

It appears that #65 isn't fixed at all. A sample configuration file from #418

    # cat etc/tempesta_fw.conf 
    cache 0;
    listen 80;
    server 127.0.0.1:8080;
    listen 80;

Produces wrong output (note that the actual error is at 4th line):

    [13936.069834] [tempesta] ERROR: configuration handler returned error: -22
    [13936.071569] [tempesta] ERROR: configuration parsing error: str:1;w:(null)
    [13936.073360] [tempesta] ERROR: can't parse configuration data
    [13936.075681] [tempesta] ERROR: failed to start modules

Firstly, the line is wrong. Secondly, str:1;w:(null) looks too cryptic: w should show the actual line, but it doesn't. So we have to show an actual error line to a user. Finally, 4 error messages are shown to a user, that's too much. At least 3rd line doubles the 2nd one. Probably 1st line also isn't required.

The lines number is quite important because we use rate limited printing, so a user can not see the errors at all in case of several restarts. (Actually I faced the case during my tests). A possible solution could be introducing special TFW_{ERR,WARN,etc} macro w/o rate limiting. The macros should be used at startup and shutdown cases only, when we know exactly that there won't be a lot of messages and they're crucial for a user.

In general configuration error must be shown in user friendly manner. So that it's easy for a user to understand what they did wrong.

Please also address code dirtiness in ed366efa , e.g. ed366efa#diff-5b6567e29085fde4971054cd52df15a5R393

Crucial since directly affects user experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants