Skip to content

Commit

Permalink
Syntax error in configuration now fails the manager. making the exit …
Browse files Browse the repository at this point in the history
…code 1 on syntax error
  • Loading branch information
yoavtzelnick authored and buglloc committed Nov 10, 2017
1 parent ea7d771 commit 0f9b192
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 11 additions & 7 deletions gixy/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from gixy.core.plugins_manager import PluginsManager
from gixy.core.config import Config
from gixy.cli.argparser import create_parser
from gixy.core.exceptions import InvalidConfiguration


LOG = logging.getLogger()

Expand Down Expand Up @@ -158,13 +160,15 @@ def main():
continue

with Gixy(config=config) as yoda:
if path == '-':
with os.fdopen(sys.stdin.fileno(), 'rb') as fdata:
yoda.audit('<stdin>', fdata, is_stdin=True)
else:
with open(path, mode='rb') as fdata:
yoda.audit(path, fdata, is_stdin=False)

try:
if path == '-':
with os.fdopen(sys.stdin.fileno(), 'rb') as fdata:
yoda.audit('<stdin>', fdata, is_stdin=True)
else:
with open(path, mode='rb') as fdata:
yoda.audit(path, fdata, is_stdin=False)
except InvalidConfiguration:
failed = True
formatter.feed(path, yoda)
failed = failed or sum(yoda.stats.values()) > 0

Expand Down
2 changes: 2 additions & 0 deletions gixy/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class InvalidConfiguration(Exception):
pass
5 changes: 2 additions & 3 deletions gixy/parser/nginx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fnmatch

from pyparsing import ParseException

from gixy.core.exceptions import InvalidConfiguration
from gixy.parser import raw_parser
from gixy.directives import block, directive

Expand All @@ -29,7 +29,6 @@ def parse_file(self, path, root=None):
def parse(self, content, root=None, path_info=None):
if not root:
root = block.Root()

try:
parsed = self.parser.parse(content)
except ParseException as e:
Expand All @@ -38,7 +37,7 @@ def parse(self, content, root=None, path_info=None):
LOG.error('Failed to parse config "{file}": {error}'.format(file=path_info, error=error_msg))
else:
LOG.error('Failed to parse config: {error}'.format(error=error_msg))
return root
raise InvalidConfiguration(error_msg)

if len(parsed) and parsed[0].getName() == 'file_delimiter':
# Were parse nginx dump
Expand Down

0 comments on commit 0f9b192

Please sign in to comment.