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

[incubator-kie-drools-6016] Emit a warning when an eval is improperly… #6024

Merged

Conversation

tkobayas
Copy link
Contributor

@tkobayas tkobayas linked an issue Jul 12, 2024 that may be closed by this pull request
Comment on lines +234 to +241
public static void logWarnIfImproperEval(EvalCondition evalCondition, String evalExpression) {
if (warnLogCounter == 10) {
warnLogCounter++;
LOG.warn("More eval warnings will be suppressed...");
return;
} else if (warnLogCounter > 10) {
return; // avoid flooding the logs
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log a maximum of 10 warnings, because I guess if a user likes to use eval, there would be tons of warnings. 10 logs would be enough to get attention.

@tkobayas tkobayas marked this pull request as draft July 14, 2024 16:59
Comment on lines +248 to +257
for (Declaration declaration : evalCondition.getRequiredDeclarations()) {
if (declaration.getPattern() != null) {
sb.append("'");
sb.append(declaration.getIdentifier());
sb.append("' comes from previous pattern '");
String className = declaration.getPattern().getObjectType().getClassName();
sb.append(className.substring(className.lastIndexOf('.') + 1));
sb.append("'. ");
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The criteria of the warning is "If the eval uses a declaration which comes from previous pattern". I guess, most of eval usages meet the case. Do you think of other criteria? @mariofusco

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is also what I had in mind. I cannot think to any other condition at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll go with it.

@tkobayas tkobayas marked this pull request as ready for review July 16, 2024 07:26
@tkobayas tkobayas requested review from baldimir and pibizza July 17, 2024 01:24
Copy link
Contributor

@pibizza pibizza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@baldimir baldimir merged commit bd28a79 into apache:main Jul 29, 2024
19 checks passed
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Aug 6, 2024
rodrigonull pushed a commit to rodrigonull/incubator-kie-drools that referenced this pull request Oct 7, 2024
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

Successfully merging this pull request may close these issues.

Emit a warning when an eval is improperly and unnecessarily used
4 participants