Skip to content

ComboBreaker exception that breaks the validation chain #166

Open
@jayd3e

Description

@jayd3e

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions