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

Improve the handling of syntax errors to give better error reporting #22

Open
snigel opened this issue Aug 18, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@snigel
Copy link

snigel commented Aug 18, 2022

If a configuration block isn't closed with '}' nginx-linter will crash with the following message:

Unexpected error: Error: Failed to parse: test.conf
Caused by:
SyntaxError: Expected " ", "#", "\n", "\r", "\t", "access_by_lua_block", "balancer_by_lua_block", "body_filter_by_lua_block", "content_by_lua_block", "header_filter_by_lua_block", "init_by_lua_block", "init_worker_by_lua_block", "log_by_lua_block", "rewrite_by_lua_block", "set_by_lua_block", "ssl_certificate_by_lua_block", "ssl_session_fetch_by_lua_block", "ssl_session_store_by_lua_block", "}", or any character but end of input found.
at parseFile (/opt/homebrew/lib/node_modules/nginx-linter/lib/parser/index.js:22:15)
at Array.map ()
at Object.parseFiles (/opt/homebrew/lib/node_modules/nginx-linter/lib/parser/index.js:31:23)
at validate (/opt/homebrew/lib/node_modules/nginx-linter/bin/_cli/commands.js:75:28)
at execute (/opt/homebrew/lib/node_modules/nginx-linter/bin/_cli/commands.js:51:20)
at Object.main (/opt/homebrew/lib/node_modules/nginx-linter/bin/_cli/commands.js:168:16)
at Object. (/opt/homebrew/lib/node_modules/nginx-linter/bin/nginx-linter.js:6:24)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
at Module.load (node:internal/modules/cjs/loader:998:32)

It would be helpful if the linter could give some hints on what character it's looking for or where in the configuration this is happening.

@jhinch jhinch changed the title Linter crash if block isn't closed. Improve the handling of syntax errors to give better error reporting Aug 18, 2022
@jhinch jhinch added the enhancement New feature or request label Aug 18, 2022
@jhinch
Copy link
Owner

jhinch commented Aug 18, 2022

Currently the linter assumes valid nginx configuration is provided as input and isn't designed to handle syntax issues.

The current error does report what characters its expecting next but it would need a special handling around end of file to narrow the possible options its looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants