Browse Source

Nicer exception when bad json string

pull/22/head
Louis 11 years ago
parent
commit
7487a1b911
  1. 19
      songbook_core/templates.py

19
songbook_core/templates.py

@ -183,8 +183,9 @@ class TexRenderer(object):
""" """
subvariables = {} subvariables = {}
templatename = self.texenv.get_template(template).filename
with codecs.open( with codecs.open(
self.texenv.get_template(template).filename, templatename,
'r', 'r',
'utf-8' 'utf-8'
) as template_file: ) as template_file:
@ -193,7 +194,21 @@ class TexRenderer(object):
match = re.findall(VARIABLE_REGEXP, content) match = re.findall(VARIABLE_REGEXP, content)
if match: if match:
for var in match: for var in match:
subvariables.update(json.loads(var)) try:
subvariables.update(json.loads(var))
except ValueError as exception:
raise errors.TemplateError(
exception,
(
"Error while parsing json in file "
"{filename}. The json string was:"
"\n'''\n{jsonstring}\n'''"
).format(
filename=templatename,
jsonstring=var,
)
)
return (subvariables, subtemplates) return (subvariables, subtemplates)
def render_tex(self, output, context): def render_tex(self, output, context):

Loading…
Cancel
Save