nginx-linter icon indicating copy to clipboard operation
nginx-linter copied to clipboard

Improve the handling of syntax errors to give better error reporting

Open snigel opened this issue 2 years ago • 1 comments

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.

snigel avatar Aug 18 '22 13:08 snigel

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

jhinch avatar Aug 18 '22 20:08 jhinch