Browse Source

Nicer exception when bad json string

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

17
songbook_core/templates.py

@ -183,8 +183,9 @@ class TexRenderer(object):
"""
subvariables = {}
templatename = self.texenv.get_template(template).filename
with codecs.open(
self.texenv.get_template(template).filename,
templatename,
'r',
'utf-8'
) as template_file:
@ -193,7 +194,21 @@ class TexRenderer(object):
match = re.findall(VARIABLE_REGEXP, content)
if match:
for var in match:
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)
def render_tex(self, output, context):

Loading…
Cancel
Save