Skip to content
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

ComboBreaker exception that breaks the validation chain #166

Open
jayd3e opened this issue Feb 9, 2014 · 0 comments
Open

ComboBreaker exception that breaks the validation chain #166

jayd3e opened this issue Feb 9, 2014 · 0 comments

Comments

@jayd3e
Copy link
Contributor

jayd3e commented Feb 9, 2014

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant