Skip to content

Eval() or Run() not returning an error. #198

@loosbrecht

Description

@loosbrecht

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions