Improve logging for template syntax errors
The shlex splitting can fail, resulting in error messages like: ERROR livemedia-creator: No closing quotation without any context in the log files. This logs the line that failed to be split and expanded. Related: rhbz#1689314
This commit is contained in:
parent
c15a976832
commit
05128a76fd
@ -69,11 +69,17 @@ class LoraxTemplate(object):
|
|||||||
# mako template now returns unicode strings
|
# mako template now returns unicode strings
|
||||||
lines = map(lambda line: line.encode("utf8"), lines)
|
lines = map(lambda line: line.encode("utf8"), lines)
|
||||||
|
|
||||||
# split with shlex and perform brace expansion
|
# split with shlex and perform brace expansion. This can fail, so we unroll the loop
|
||||||
lines = map(split_and_expand, lines)
|
# for better error reporting.
|
||||||
|
expanded_lines = []
|
||||||
self.lines = lines
|
try:
|
||||||
return lines
|
for line in lines:
|
||||||
|
expanded_lines.append(split_and_expand(line))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error('shlex error processing "%s": %s', line, str(e))
|
||||||
|
raise
|
||||||
|
self.lines = expanded_lines
|
||||||
|
return expanded_lines
|
||||||
|
|
||||||
def split_and_expand(line):
|
def split_and_expand(line):
|
||||||
return [exp for word in shlex.split(line) for exp in brace_expand(word)]
|
return [exp for word in shlex.split(line) for exp in brace_expand(word)]
|
||||||
|
Loading…
Reference in New Issue
Block a user