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

[new-parser] Add error listener to DrlExprParser #5778

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

yurloc
Copy link
Contributor

@yurloc yurloc commented Mar 11, 2024

Add an error listener to the expression parser that collects errors and stores them in the helper.

This slightly increases the number of failing tests but fewer of them are actually visible because the build fails earlier and the module with the most failing tests drools-model-codegen is now skipped. The build will return to a "normal" state (before this PR) once we fix #5702, which I'm already working on.

How to replicate CI configuration locally?

Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use build-chain tool to handle cross repository builds and be sure that we always use latest version of the code for each repository.

build-chain tool is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See local execution details to get more information about it.

How to retest this PR or trigger a specific build:
  • for pull request and downstream checks

    • Push a new commit to the PR. An empty commit would be enough.
  • for a full downstream build

    • for github actions job: add the label run_fdb
  • for Jenkins PR check only

@yurloc yurloc changed the title Add error listener to DrlExprParser [new-parser] Add error listener to DrlExprParser Mar 11, 2024
if (parser.hasErrors()) {
for (DroolsParserException error : parser.getErrors()) {
registerDescrBuildError(context, patternDescr,
"Unable to parse pattern expression:\n" + error.getMessage());
}
return null;
}
result.setResource(patternDescr.getResource());
result.copyLocation(original);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parser.hasErrors() check needs to be performed before accessing result. If the parsers has errors, result is null.

@@ -55,7 +55,7 @@ public String getOperator() {
}

public void setOperator( String operator ) {
this.operator = operator.trim();
this.operator = operator != null ? operator.trim() : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to avoid an NPE in org.drools.drl.parser.antlr4.DRLExprParserTest#testNoViableAlt.

}
@Test
public void testNoViableAlt() {
String source = "a~a";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confess that I discovered this by chance. I'm not sure why this causes the NoViableAltException but I couldn't come up with anything better.

e.getOffendingToken().getStartIndex(),
public DroolsParserException createDroolsException(Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e ) {
return new DroolsParserException( determineErrorCode( e ),
String.format("Line %d:%d %s", line, charPositionInLine, message),
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 message produced by the parser is almost identical to the original message. It just needs prepending the line/column information. That allows me to drop the createErrorMessage and the formatting strings.

if ( state.errorRecovery ) {
return;
}
state.errorRecovery = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error recovery is handled by the parser's DefaultErrorStrategy.

@yurloc yurloc marked this pull request as ready for review March 12, 2024 14:37
@yurloc
Copy link
Contributor Author

yurloc commented Mar 12, 2024

@tkobayas @mariofusco, optionally @gitgabrio please review.

@mariofusco mariofusco merged commit c65a1a0 into apache:dev-new-parser Mar 13, 2024
0 of 5 checks passed
@yurloc yurloc deleted the drl-expr-error-listener branch March 15, 2024 09:58
@yurloc
Copy link
Contributor Author

yurloc commented Mar 18, 2024

Fixing progress: There were 99 failed tests (inaccurate because drools-model-codegen is skipped).

tkobayas pushed a commit to tkobayas/drools that referenced this pull request Jun 11, 2024
tkobayas pushed a commit to tkobayas/drools that referenced this pull request Oct 2, 2024
tkobayas pushed a commit to tkobayas/drools that referenced this pull request Oct 11, 2024
tkobayas pushed a commit that referenced this pull request Oct 11, 2024
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Oct 24, 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.

4 participants