gorules / zen

Open-source Business Rules Engine for your Rust, NodeJS, Python or Go applications.
https://gorules.io
MIT License
667 stars 61 forks source link

Integrating multiple decision nodes leads to error "missing field `nodes`" #164

Closed raunakkathuria closed 1 month ago

raunakkathuria commented 1 month ago

Problem

I am trying to have multiple decision rules for the same input, I tried https://github.com/gorules/zen/issues/61 but when I add an external decision model, it always gives the error

Loader failed internally on key signup/country landing company.json: missing field `nodes` at line 1 column 2.

Details

Country landing company rule

My country landing company JSON which I am using in another rule Signup

image country_landing_company.json

Signup rule

image graph.json

An when I run the Go program

package main

import (
    "fmt"
    "os"
    "path"

    "github.com/gorules/zen-go"
)

func readTestFile(key string) ([]byte, error) {
    filePath := path.Join("test-data", key)
    return os.ReadFile(filePath)
}

func main() {
    engine := zen.NewEngine(zen.EngineConfig{Loader: readTestFile})
    defer engine.Dispose() // Call to avoid leaks

    output, err := engine.Evaluate("signup/graph.json", map[string]any{"residence": "es", "account": "real"})
    if err != nil {
        fmt.Println(err)
    }

    fmt.Printf("%s", output)
}

It gives me the following error

go run main.go 
{"nodeId":"e2da6563-ac5f-4a15-a5f1-daf89e1a241f","source":"Depth limit exceeded","type":"NodeError"}
%!s(*zen.EvaluationResponse=<nil>)

If I don't embed and directly use a decision table, it works

image

gomugomu0034 commented 1 month ago

You need to publish the decision model you are trying to embed first and then run your tests

raunakkathuria commented 1 month ago

Thanks that worked. Maybe mention that in the document.

Still getting the error for the Go program

{"nodeId":"b5d45e09-d633-4e30-a7e8-2fb9e1b02097","source":"Depth limit exceeded","type":"NodeError"}
%!s(*zen.EvaluationResponse=<nil>)

I will raise it on the respective repository then.