mirror of https://github.com/yandex/gixy
Syntax error in configuration now fails the manager. making the exit code 1 on syntax error
parent
ea7d771ab6
commit
0f9b192c13
|
@ -9,6 +9,8 @@ from gixy.formatters import get_all as formatters
|
|||
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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
class InvalidConfiguration(Exception):
|
||||
pass
|
|
@ -4,7 +4,7 @@ import logging
|
|||
import fnmatch
|
||||
|
||||
from pyparsing import ParseException
|
||||
|
||||
from gixy.core.exceptions import InvalidConfiguration
|
||||
from gixy.parser import raw_parser
|
||||
from gixy.directives import block, directive
|
||||
|
||||
|
@ -29,7 +29,6 @@ class NginxParser(object):
|
|||
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:
|
||||
|
@ -38,7 +37,7 @@ class NginxParser(object):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue