Skip to content

Commit 369d3b1

Browse files
committed
Unified SyntaxError messages
1 parent bed59fb commit 369d3b1

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

adafruit_templateengine.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _resolve_includes(template: str):
219219

220220
def _check_for_unsupported_nested_blocks(template: str):
221221
if _find_block(template) is not None:
222-
raise ValueError("Nested blocks are not supported")
222+
raise SyntaxError("Nested blocks are not supported")
223223

224224

225225
def _resolve_includes_blocks_and_extends(template: str):
@@ -248,7 +248,7 @@ def _resolve_includes_blocks_and_extends(template: str):
248248
endblock_match = _find_named_endblock(template, block_name)
249249

250250
if endblock_match is None:
251-
raise ValueError(r"Missing {% endblock %} for block: " + block_name)
251+
raise SyntaxError("Missing {% endblock %} for block: " + block_name)
252252

253253
block_content = template[block_match.end() : endblock_match.start()]
254254

@@ -457,7 +457,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
457457
indentation_level -= 1
458458

459459
if not nested_if_statements:
460-
raise SyntaxError("No matching {% if ... %} block for {% endif %}")
460+
raise SyntaxError("Missing {% if ... %} block for {% endif %}")
461461

462462
nested_if_statements.pop()
463463

@@ -479,9 +479,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
479479
indentation_level -= 1
480480

481481
if not nested_for_loops:
482-
raise SyntaxError(
483-
"No matching {% for ... %} block for {% endfor %}"
484-
)
482+
raise SyntaxError("Missing {% for ... %} block for {% endfor %}")
485483

486484
nested_for_loops.pop()
487485

@@ -496,7 +494,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
496494

497495
if not nested_while_loops:
498496
raise SyntaxError(
499-
"No matching {% while ... %} block for {% endwhile %}"
497+
"Missing {% while ... %} block for {% endwhile %}"
500498
)
501499

502500
nested_while_loops.pop()
@@ -517,7 +515,7 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
517515
elif token == r"{% endautoescape %}":
518516
if not nested_autoescape_modes:
519517
raise SyntaxError(
520-
"No matching {% autoescape ... %} block for {% endautoescape %}"
518+
"Missing {% autoescape ... %} block for {% endautoescape %}"
521519
)
522520

523521
nested_autoescape_modes.pop()
@@ -534,15 +532,15 @@ def _create_template_rendering_function( # pylint: disable=,too-many-locals,too
534532
# Checking for unclosed blocks
535533
if len(nested_if_statements) > 0:
536534
last_if_statement = nested_if_statements[-1]
537-
raise SyntaxError(f"Missing {{% endif %}} for {last_if_statement}")
535+
raise SyntaxError("Missing {% endif %} for " + last_if_statement)
538536

539537
if len(nested_for_loops) > 0:
540538
last_for_loop = nested_for_loops[-1]
541-
raise SyntaxError(f"Missing {{% endfor %}} for {last_for_loop}")
539+
raise SyntaxError("Missing {% endfor %} for " + last_for_loop)
542540

543541
if len(nested_while_loops) > 0:
544542
last_while_loop = nested_while_loops[-1]
545-
raise SyntaxError(f"Missing {{% endwhile %}} for {last_while_loop}")
543+
raise SyntaxError("Missing {% endwhile %} for " + last_while_loop)
546544

547545
# No check for unclosed autoescape blocks, as they are optional and do not result in errors
548546

0 commit comments

Comments
 (0)