cloud-custodian / cel-python

Pure Python implementation of the Common Expression Language
Apache License 2.0
99 stars 20 forks source link

Getting a TypeError instead of evaluation error #41

Open danj opened 1 year ago

danj commented 1 year ago

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

hardbyte commented 1 year ago

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]}
slott56 commented 1 month ago

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.