hyperjumptech / grule-rule-engine

Rule engine implementation in Golang
Other
2.2k stars 340 forks source link

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

Open PaulForgey-Discovery opened 11 months ago

PaulForgey-Discovery commented 11 months ago

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

BubbleGarten commented 8 months ago

Strongly agree