Skip to content

Commit 6d2e656

Browse files
committed
improve handling of malformed jinja templates
1 parent 7f65ce2 commit 6d2e656

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

jinja2html/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ def build_html(path):
234234
config = JINJA_WATCH_PATH / "config.json"
235235
context = json.loads(config.read_text()) if config.is_file() else {}
236236

237-
output = t_env.get_template(str(path)).render(context)
238-
if DEV_MODE:
239-
try:
237+
try:
238+
output = t_env.get_template(str(path)).render(context)
239+
240+
if DEV_MODE:
241+
# try:
240242
soup = BeautifulSoup(output, "lxml")
241243
body_tag = soup.find("body")
242244

@@ -249,10 +251,13 @@ def build_html(path):
249251
body_tag.append(soup.new_tag("script", src="https://cdnjs.cloudflare.com/ajax/libs/livereload-js/3.3.1/livereload.min.js",
250252
integrity="sha512-DSycG/J5pRCjy6wZ8nfeqaKuSAf9jVmSulTuzy1xQL+2yyBIp7fwzNvx+tZCtZ6kIRMqiDyWOYSl4zYjT32zOw==", crossorigin="anonymous"))
251253
output = str(soup)
252-
except AttributeError:
253-
logging.warning(output := f"Malformed or non-existent html in '{path}'. Doing nothing.")
254254

255-
resolve_output_path(path).write_text(output)
255+
resolve_output_path(path).write_text(output)
256+
257+
except AttributeError:
258+
logging.warning("Malformed or non-existent html in '%s'. Doing nothing.", path)
259+
except Exception as e:
260+
logging.exception(e)
256261

257262

258263
def main():

0 commit comments

Comments
 (0)