From 2e573a94b14cf87e81559d5130af71df2d3b1ca8 Mon Sep 17 00:00:00 2001 From: Philipp Keller <11523+philippkeller@users.noreply.github.com> Date: Sat, 23 Sep 2023 15:47:10 +0200 Subject: [PATCH] fix line_num when handlebar rendering is failing --- pybars/_compiler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pybars/_compiler.py b/pybars/_compiler.py index becc692..aa3df58 100644 --- a/pybars/_compiler.py +++ b/pybars/_compiler.py @@ -828,12 +828,13 @@ def _generate_code(self, source): print('') if position < len(source): - line_num = source.count('\n') + 1 beginning_of_line = source.rfind('\n', 0, position) if beginning_of_line == -1: char_num = position + line_num = 1 else: char_num = position - beginning_of_line + line_num = source[:beginning_of_line+1].count('\n') + 1 word = self._extract_word(source, position) raise PybarsError("Error at character %s of line %s near %s" % (char_num, line_num, word))