cloud-custodian/cel-python

Getting a TypeError instead of evaluation error

danj opened this issue · 2 comments

danj commented

Getting the wrong exception type when expression uses all
Expect to get an CELEvalError but instead of a TypeError

import celpy
from celpy import CELEvalError

env = celpy.Environment()

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    all_positive = "data.all(x, x>0)"
    breaks = {'data_': [1, 2, 3] }

    ast = env.compile(all_positive)
    prgm = env.program(ast)

    try:
        prgm.evaluate(breaks)
    except CELEvalError as ex:
        print('Got an evaluation error')
    except TypeError as ex:
        print('Got a type error')

Happy to try and fix with some guidance

I'm curious why your context has data_ where your expression uses data - just to expose the issue right?

For reference, I see an evaluation error using:

    all_positive = "data.all(x, x > 0)"
    breaks = {'data': [1, 2, '3']}

But a type error using:

    all_positive = "true || data.all(x, x > 0)"
    breaks = {'data_': [1, 2, 3]}

I'm not sure what the baseline Golang CEL implementation does. If anyone has an example from the Go implementation, that would be helpful.

I am confident it does not expose a Python exception; it seems more likely that it returns a CEL error code.