You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to execute a rule that involves a custom function CheckProductCondition which checks conditions on a slice of Product structs, Grule encounters a panic with an error related to improper use of reflection (reflect: call of reflect.Value.Elem on slice Value). This error suggests that there might be an issue with how Grule handles reflection operations on slices within custom functions.
Steps to Reproduce:
Define a struct Product.
Define a struct ValidationFact containing a slice of Product.
Implement a method CheckProductCondition on ValidationFact to check for a condition across all products using a custom function passed as a parameter.
Attempt to execute a rule that uses CheckProductCondition.
The rule engine panics upon execution.
Expected Behavior:
The rule should execute without errors, correctly using the custom function to evaluate conditions on each element of the product slice.
Actual Behavior:
The rule engine throws a panic error related to reflection operations, specifically when attempting to handle a slice within the rule execution context.
Code Snippet:
typeProductstruct {
ProductNamestringProductTypestringValidint
}
typeValidationFactstruct {
products []Product
}
func (ps*ValidationFact) CheckProductCondition(propName, expectedValuestring, conditionFuncfunc(string, string) bool) bool {
for_, p:=rangeps.products {
switchpropName {
case"ProductName":
ifconditionFunc(p.ProductName, expectedValue) {
returntrue
}
}
}
returnfalse
}
// Function used as argumentfuncstartsWith(input, prefixstring) bool {
returnstrings.HasPrefix(input, prefix)
}
// Rule definition causing the panicrulePhoneNeedToStartWithI"Phone name needs to start with I"salience10 {
whenValidationFact.CheckProductCondition("ProductName", "I", startsWith) ==truethenLog("Non-compliant product found.");
}
Environment:
Grule version: 1.15
Go version: 1.21.5
Operating System and version: Ubuntu 20.04
Impact:
This issue prevents the implementation of dynamic condition checking within rules, limiting the flexibility and utility of the rule engine for scenarios involving collections of items.
The text was updated successfully, but these errors were encountered:
When attempting to execute a rule that involves a custom function CheckProductCondition which checks conditions on a slice of Product structs, Grule encounters a panic with an error related to improper use of reflection (reflect: call of reflect.Value.Elem on slice Value). This error suggests that there might be an issue with how Grule handles reflection operations on slices within custom functions.
Steps to Reproduce:
Expected Behavior:
The rule should execute without errors, correctly using the custom function to evaluate conditions on each element of the product slice.
Actual Behavior:
The rule engine throws a panic error related to reflection operations, specifically when attempting to handle a slice within the rule execution context.
Code Snippet:
Environment:
Impact:
This issue prevents the implementation of dynamic condition checking within rules, limiting the flexibility and utility of the rule engine for scenarios involving collections of items.
The text was updated successfully, but these errors were encountered: