Skip to content

Commit 4bfa442

Browse files
committed
fix(ast): refactor error messages in Evaluate function to use RuleEntry's RuleName directly
because during the first pass,the rule name is not yet set in the dataContext which causes nilPointer exception.
1 parent 44361ec commit 4bfa442

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ast/RuleEntry.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ package ast
1717
import (
1818
"context"
1919
"fmt"
20-
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
2120
"reflect"
2221
"strings"
2322

23+
"github.com/hyperjumptech/grule-rule-engine/ast/unique"
24+
2425
"github.com/hyperjumptech/grule-rule-engine/pkg"
2526
)
2627

@@ -183,11 +184,11 @@ func (e *RuleEntry) Evaluate(ctx context.Context, dataContext IDataContext, memo
183184
if err != nil {
184185
AstLog.Errorf("Error while evaluating rule %s, got %v", e.RuleName, err)
185186

186-
return false, fmt.Errorf("evaluating expression in rule '%s' the when raised an error. got %v", dataContext.GetRuleEntry().RuleName, err)
187+
return false, fmt.Errorf("evaluating expression in rule '%s' the when raised an error. got %v", e.RuleName, err)
187188
}
188189
if val.Kind() != reflect.Bool {
189190

190-
return false, fmt.Errorf("evaluating expression in rule '%s', the when is not a boolean expression : %s", dataContext.GetRuleEntry().RuleName, e.WhenScope.Expression.GetGrlText())
191+
return false, fmt.Errorf("evaluating expression in rule '%s', the when is not a boolean expression : %s", e.RuleName, e.WhenScope.Expression.GetGrlText())
191192
}
192193

193194
return val.Bool(), nil

0 commit comments

Comments
 (0)