From 7fb230a8f8e8be7627e0833e3f97a63f36917041 Mon Sep 17 00:00:00 2001 From: JHoloboski Date: Thu, 3 Dec 2015 15:45:32 -0600 Subject: [PATCH] replace asserts with nicer ValueErrors in gyb --- utils/gyb.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/gyb.py b/utils/gyb.py index 91af3a4e8c9b0..b26d68f6329e9 100755 --- a/utils/gyb.py +++ b/utils/gyb.py @@ -466,7 +466,8 @@ def tokenGenerator(self, baseTokens): if (kind == 'gybBlockOpen'): # Absorb any '}% \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' @@ -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