hyperjumptech/grule-rule-engine

a fact's functions should be able to return an error

PaulForgey-Discovery opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
If an error occurs within the execution of a custom function being called from a rule, I want to handle it gracefully after the execution properly fails.

Describe the solution you'd like
At present, the function can return either 0 or 1 values. It should be able to return one one of:

func()
func() error
func() value
func() value, error

This error should be ultimately returned from engine.ExecuteWithContext. It probably should also be wrapped around grule's own error classifying it as an error returned from such a function.

This is (arguably) a bit more idiomatic go when supporting callbacks like this. Additionally, it would be nice for such functions to be able to take a context.Context as their first parameter.

Describe alternatives you've considered
panic/recover, which has several potential problems.

Additional context

Strongly agree