-
-
Notifications
You must be signed in to change notification settings - Fork 473
Closed
Labels
Description
I'm trying to use a rule that is able to return an error. But I only get the first return value back.
I even tried to use the example code but even there I don't get an error back.
The code below prints out 0 and not the error as expected.
package main
import (
"errors"
"fmt"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]interface{}{
"foo": -1,
"double": func(i int) (int, error) {
if i < 0 {
return 0, errors.New("value cannot be less than zero")
}
return i * 2,nil
},
}
out, err := expr.Eval("double(foo)", env)
// This `err` will be the one returned from `double` function.
// err.Error() == "value cannot be less than zero"
if err != nil {
panic(err)
}
fmt.Print(out)
}
p.s. Returning errors contains an error in the example at line 16. This should be return i * 2, nil