-
-
Notifications
You must be signed in to change notification settings - Fork 471
Closed
Description
Error is swallowed when using expr.ConstExpr(...) optimization with a custom function that has a signature which returns an error: func(i int) (int, error).
This example works correctly if expr.ConstExpr(...) setting is omitted, or optimizations are turned off. The error would be returned by expr.Run(...).
package main
import (
"errors"
"fmt"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]interface{}{
"double": func(i int) (int, error) {
if i < 0 {
return 0, errors.New("value cannot be less than zero")
}
return i * 2, nil
},
}
options := []expr.Option{
expr.Env(env),
expr.ConstExpr("double"),
}
// err == nil here. Error is swallowed.
compiledRule, err := expr.Compile("double(-1)", options...)
if err == nil {
fmt.Printf("expected expr.Compile to return error")
} else {
fmt.Println("success")
}
// err == nil here as well.
_, err = expr.Run(compiledRule, env)
}
Metadata
Metadata
Assignees
Labels
No labels