Fix: Prevent nil pointer dereference when reporting rule evaluation errors#493
Merged
newm4n merged 1 commit intohyperjumptech:masterfrom Jul 18, 2025
Merged
Fix: Prevent nil pointer dereference when reporting rule evaluation errors#493newm4n merged 1 commit intohyperjumptech:masterfrom
newm4n merged 1 commit intohyperjumptech:masterfrom
Conversation
…ry's RuleName directly because during the first pass,the rule name is not yet set in the dataContext which causes nilPointer exception.
Contributor
Author
|
@newm4n hey could you please take a look at this ☝🏾 |
newm4n
approved these changes
Jul 18, 2025
Collaborator
newm4n
left a comment
There was a problem hiding this comment.
This is correct, when you know that the rule not exist, there's no reason to get the rule name using the non-existent rule. Thats silly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a rule contains an invalid function/field(s) in its [when] expression, the engine logs the error but then panics with a nil pointer dereference.
This happens because the error reporting
(Line 186):tries to access
dataContext.GetRuleEntry().RuleNamebefore SetRuleEntry is called inengine.go, resulting in a nil pointer dereference.How to Reproduce
Use a rule with an invalid function in the [when] clause, for example:
Here,
IsInis not a valid function for a string in Grule.Observed Behavior
The AST logger prints the actual error
(Line 184):But instead of returning this error to the caller, the engine panics and returns the below error message which could be misleading to the caller of the rule-engine :
Solution
Change the error reporting to use the current RuleEntry's
e.RuleNamedirectly, rather than accessing it viadataContext.GetRuleEntry(), as the code anyway usese.RuleNameto prepare the AST logger error message.This ensures error messages are constructed safely, even if the rule's name has not yet been set in the data context.
Code Fix
Before:
After:
Impact
Prevents engine panics when evaluating rules with invalid syntax.
Ensures errors are returned to the caller as expected.
No impact on valid rule execution or rule selection logic