colander
colander copied to clipboard
ComboBreaker exception that breaks the validation chain
Proposing that we create an exception that can be raised in a validator, which indicates an Invalid state AND stops the validation chain. I have something hacked together which accomplishes this:
class ComboBreaker(colander.Invalid):
pass
class All(colander.All):
"""
Custom All validator, that allows me to throw a specific exception, if
I want to end the validation chain.
"""
def __call__(self, node, value):
excs = []
for validator in self.validators:
try:
validator(node, value)
except ComboBreaker as e:
excs.append(e)
break
except Invalid as e:
excs.append(e)
if excs:
exc = Invalid(node, [exc.msg for exc in excs])
for e in excs:
exc.children.extend(e.children)
raise exc