govaluate
govaluate copied to clipboard
Methods on LHS of comparison do not work
Given the following code:
https://gist.github.com/grepory/b132dc25329d19b42627e70a5fe0c77a
If I use a Method as an accessor on a passed in struct, and that's on the left-hand side of a comparison, e.g. foo.Method() == 'result'
, then when we go to call Eval() on the expression, we get an error:
λ go run main.go
left = <nil>, right = false, parameters = &{map[entity:0xc42000a1c0]}
panic: Method call failed - 'entity.Get': Argument type conversion failed: failed to convert 'bool' to 'string'
goroutine 1 [running]:
main.main()
/Users/grepory/go/src/github.com/grepory/test/govaluate/main.go:37 +0x35b
exit status 2
I've modified govaluate to print the arguments passed to the evaluation stage's operator function. As you can see, Get()
is being passed false
instead of team
. If I reverse the order of the comparions to 'ops' == entity.Get('team')
:
λ go run main.go
left = <nil>, right = team, parameters = &{map[entity:0xc42000a1c0]}
res = true
If I remove the argument to the Get() function altogether, it's still passed false
.
I'm trying to look into this myself, but having some difficulty quiiiite piecing it together. I will try to delve into the issue if I get the time this week.
If there's any additional information I can give you, let me know. (I'm using tip of master govaluate to test).
(grepory@oppie)(16:29:01)(~/go/src/github.com/knetic/govaluate)
λ git rev-parse HEAD
9aa49832a739dcd78a5542ff189fb82c3e423116
I highly suspect this is due to the brittle way this library handles parameter accessors (such as calling foo.Bar()
). I've been unhappy with how they work for some time, but have recently changed jobs and didn't have time to properly patch them up. I'm going to call this related to the broader set of concerns I have that were first raised with #61 . I don't have an ETA on when this will get fixed, unfortunately.
Sidenote, I'm deeply humbled that Sensu is using this library - I actually first put it together due to my frustration with Sensu at a previous job. The references in the docs to "if you have a system that operates on metrics flowing through it" was actually about (how my previous company used) Sensu.