gorules / zen-go

Open-source business rules engine for Go
https://gorules.io
MIT License
76 stars 8 forks source link

Depth limit exceeded when using decision node #18

Closed raunakkathuria closed 2 months ago

raunakkathuria commented 3 months ago

Problem

I am getting the following error when using the decision node from another file

panic: {"nodeId":"b5d45e09-d633-4e30-a7e8-2fb9e1b02097","source":"Depth limit exceeded","type":"NodeError"}

image

Steps to reproduce

raunakkathuria commented 3 months ago

The decision is compiling fine on gorules. Refer https://github.com/gorules/zen/issues/164

StewartHuang commented 3 months ago

I encountered a similar issue. I resolved my problem by switching method from engine.Evaluate to the engine.EvaluateWithOpts and manually setting EvaluationOptions.MaxDepth to 2. By the way, I believe this is a bug. In my opinion, the reason for this bug might be: In the code, the implementation of the engine.Evaluate method calls engine.EvaluateWithOpts, and passes EvaluationOptions, but does not explicitly specify the value of EvaluationOptions.MaxDepth, so the default value is set to 0, thus limiting the reference level during the execution of decision.

raunakkathuria commented 2 months ago

Thanks @StewartHuang. It worked. Here is the diff for reference if anyone stumble on the same

-   response, err := engine.Evaluate("signup/graph.json", map[string]any{"residence": "es", "account": "real"})
+ response, err := engine.EvaluateWithOpts("signup/graph.json", map[string]any{"residence": "es", "account": "real"}, zen.EvaluationOptions{
+         Trace:    true,
+         MaxDepth: 2,
+ })
+

Refer commit

raunakkathuria commented 2 months ago

Looks like different methods with different syntax. Evaluate process with no options, EvaluateWithOpts expects these options. I will close the issue as this needs to be better documented and not a functionality issue