Skip to content

Commit 1994b83

Browse files
committed
Merge pull request #106 from JHoloboski/fix/proper-raise
replace asserts with nicer ValueErrors in gyb
2 parents 9201031 + 7fb230a commit 1994b83

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: utils/gyb.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ def tokenGenerator(self, baseTokens):
466466
if (kind == 'gybBlockOpen'):
467467
# Absorb any '}% <optional-comment> \n'
468468
m2 = gybBlockClose.match(self.template, closePos)
469-
assert m2, "Invalid block closure" # FIXME: need proper error handling here.
469+
if not m2:
470+
raise ValueError("Invalid block closure")
470471
nextPos = m2.end(0)
471472
else:
472473
assert kind == 'substitutionOpen'
@@ -656,7 +657,9 @@ def execute(self, context):
656657
# Execute the code with our __children__ in scope
657658
context.localBindings['__children__'] = self.children
658659
result = eval(self.code, context.localBindings)
659-
assert context.localBindings['__children__'] is self.children
660+
661+
if context.localBindings['__children__'] is not self.children:
662+
raise ValueError("The code is not allowed to mutate __children__")
660663
# Restore the bindings
661664
context.localBindings['__children__'] = saveChildren
662665

0 commit comments

Comments
 (0)