Skip to content

replace asserts with nicer ValueErrors in gyb #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions utils/gyb.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ def tokenGenerator(self, baseTokens):
if (kind == 'gybBlockOpen'):
# Absorb any '}% <optional-comment> \n'
m2 = gybBlockClose.match(self.template, closePos)
assert m2, "Invalid block closure" # FIXME: need proper error handling here.
if not m2:
raise ValueError("Invalid block closure")
nextPos = m2.end(0)
else:
assert kind == 'substitutionOpen'
Expand Down Expand Up @@ -656,7 +657,9 @@ def execute(self, context):
# Execute the code with our __children__ in scope
context.localBindings['__children__'] = self.children
result = eval(self.code, context.localBindings)
assert context.localBindings['__children__'] is self.children

if context.localBindings['__children__'] is not self.children:
raise ValueError("The code is not allowed to mutate __children__")
# Restore the bindings
context.localBindings['__children__'] = saveChildren

Expand Down