Skip to content

Commit

Permalink
Nginx parser now returns original root if can't parse a config
Browse files Browse the repository at this point in the history
  • Loading branch information
buglloc committed Apr 28, 2017
1 parent 957f3c4 commit c63435a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gixy/parser/nginx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ def parse(self, file_path, root=None):

if not root:
root = block.Root()
parser = raw_parser.RawParser()
parsed = parser.parse(file_path)

try:
parser = raw_parser.RawParser()
parsed = parser.parse(file_path)
except ParseException as e:
LOG.error('Failed to parse config "{file}": {error}'.format(file=file_path, error=str(e)))
return root

if len(parsed) and parsed[0].getName() == 'file_delimiter':
# Were parse nginx dump
LOG.info('Switched to parse nginx configuration dump.')
Expand Down Expand Up @@ -104,10 +110,7 @@ def _resolve_file_include(self, pattern, parent):
for file_path in glob.iglob(path):
include = block.IncludeBlock('include', [file_path])
parent.append(include)
try:
self.parse(file_path, include)
except ParseException as e:
LOG.error('Failed to parse include "{file}": {error}'.format(file=file_path, error=str(e)))
self.parse(file_path, include)

if not file_path:
LOG.warning("File not found: {}".format(path))
Expand All @@ -120,10 +123,7 @@ def _resolve_dump_include(self, pattern, parent):
founded = True
include = block.IncludeBlock('include', [file_path])
parent.append(include)
try:
self.parse_block(parsed, include)
except ParseException as e:
LOG.error('Failed to parse include "{file}": {error}'.format(file=file_path, error=str(e)))
self.parse_block(parsed, include)

if not founded:
LOG.warning("File not found: {}".format(path))
Expand Down

0 comments on commit c63435a

Please sign in to comment.