Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grule engine panics #304

Closed
pablolch opened this issue May 15, 2022 · 1 comment
Closed

Grule engine panics #304

pablolch opened this issue May 15, 2022 · 1 comment

Comments

@pablolch
Copy link

pablolch commented May 15, 2022

Describe the bug
Grule engine panics and then recovers with an error:

panic: expression  1 is not on the clone table [recovered]
	panic: expression  1 is not on the clone table

To Reproduce
Steps to reproduce the behavior:

type TestData struct {
	Strings []string
}

func (f *TestData) GetStrings() []string {
	return f.Strings
}

const rule = ` rule test {
when 
	Fact.GetStrings()[0] == Fact.GetStrings()[1]
then
	Complete();
}`

func TestSliceFunctionTest(t *testing.T) {
	fact := &TestData{
		Strings: []string{"0", "0"},
	}

	dataContext := ast.NewDataContext()
	err := dataContext.Add("Fact", fact)
	assert.NoError(t, err)
	knowledgeLibrary := ast.NewKnowledgeLibrary()
	ruleBuilder := builder.NewRuleBuilder(knowledgeLibrary)
	err = ruleBuilder.BuildRuleFromResource("test", "0.0.1", pkg.NewBytesResource([]byte(rule)))
	assert.NoError(t, err)
	knowledgeBase := knowledgeLibrary.NewKnowledgeBaseInstance("test", "0.0.1")
	engine := engine.NewGruleEngine()

	err = engine.Execute(dataContext, knowledgeBase)
	assert.NoError(t, err)
}

Expected behavior
No error executing the Grule engine.

Additional context
Test logs:


--- FAIL: TestSliceFunctionTest (0.00s)
panic: expression  1 is not on the clone table [recovered]
	panic: expression  1 is not on the clone table

goroutine 6 [running]:
testing.tRunner.func1.2({0x156e480, 0xc0001ed8d0})
	/usr/local/go/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x218
panic({0x156e480, 0xc0001ed8d0})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/hyperjumptech/grule-rule-engine/ast.(*WorkingMemory).Clone(0xc00007f2c0, 0xc000233c58)
	/Users/pchamorro/go/pkg/mod/github.com/hyperjumptech/grule-rule-engine@v1.10.5/ast/WorkingMemory.go:147 +0x11ff
github.com/hyperjumptech/grule-rule-engine/ast.(*KnowledgeBase).Clone(0xc0001ca0a0, 0xc000233c58)
	/Users/pchamorro/go/pkg/mod/github.com/hyperjumptech/grule-rule-engine@v1.10.5/ast/KnowledgeBase.go:217 +0x125
github.com/hyperjumptech/grule-rule-engine/ast.(*KnowledgeLibrary).NewKnowledgeBaseInstance(0xc000233e30, {0x1638db6, 0x0}, {0x1638f28, 0x5})
	/Users/pchamorro/go/pkg/mod/github.com/hyperjumptech/grule-rule-engine@v1.10.5/ast/KnowledgeBase.go:125 +0x194

@newm4n
Copy link
Member

newm4n commented May 31, 2022

Fixed with #306

@newm4n newm4n closed this as completed May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants