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

Make protocol assertions show nicer errors for selected expression types #170

Open
MichaelClerx opened this issue Apr 27, 2020 · 3 comments

Comments

@MichaelClerx
Copy link
Contributor

E.g. "assert x == 2" could return "Assertion failed: 2000 != 2" instead of just "Assertain failed" with "x == 2" somewhere in the stacktrace

@MichaelClerx
Copy link
Contributor Author

This works, but is probably not OK for some reason

class Assert(AbstractStatement):
    """
    Assertion used within a protocol.
    """
    def __init__(self, expr):
        super(Assert, self).__init__()
        self.expr = expr

    def evaluate(self, env):
        result = self.expr.evaluate(env)
        try:
            ok = result.value
        except AttributeError:
            raise ProtocolError("Assertion did not yield a Simple value or 0-d Array.")
        if not ok:
            if isinstance(self.expr, E.Eq):
                operands = self.expr.evaluate_children(env)
                lhs = operands[0].value
                rhs = operands[1].value
                raise ProtocolError(f'Assertion failed: {lhs} != {rhs}.')
            raise ProtocolError("Assertion failed.")
        return V.Null()

@jonc125
Copy link
Contributor

jonc125 commented Apr 27, 2020

That sounds reasonable to me!

MichaelClerx added a commit that referenced this issue Apr 27, 2020
@MichaelClerx
Copy link
Contributor Author

It may be worth it to add a close() method to the protocol language, that shows both arguments (unless they're vectors) ?

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

2 participants