The Error Codes
Drools Parsing Errors: Understanding Common Issues
When working with Drools, parsing errors can be tricky. Below is a table of common errors, what they mean, and how to resolve them.DRL Error Structure Visualization Methods
- 1st Block: Error code
- 2nd Block: Line and column in the DRL source where the error occurred
- 3rd Block: Description of the problem
- 4th Block: Component in the DRL source (rule, function, query) where the error occurred
- 5th Block: Pattern in the DRL source where the error occurred (if applicable)
Spelling Issue - No Viable Alternative
Example rule with incorrect spelling.Existsis spelt wrong and isexitsso the rule talks Must beexists.
Rule without a Name
Example rule without a rule name.- Must be
rule "rule name"(orrule rule_nameif no spacing). There is a requirement of a rule name to be present.
when but expected the rule name, so it flags when as the incorrect expected token.
Incorrect Syntax Usage
Example rule with incorrect syntax- This is missing a closing quotation on the
Andyparameter.
- This is missing a closing quotation on the
Andyparameter.
0:-1 means the parser reached the end of the source file (<eof>) but encountered incomplete constructs, usually due to missing quotation marks "…", apostrophes '…', or parentheses (…).
102: mismatched input
Indicates that the parser expected a particular symbol that is missing at the current input position.
Incomplete Rule Statement
Example rule with an incomplete rule statement.0:-1 means the parser reached the end of the source file (<eof>) but encountered incomplete constructs, usually due to missing quotation marks "…", apostrophes '…', or parentheses (…).
Example rule with incorrect syntax.
- Must use
&&operators instead of commas,
, with && operators resolves all errors. If you encounter multiple errors, resolve one at a time in case errors are consequences of previous errors.
103: failed predicate
Indicates that a validating semantic predicate evaluated to false.
These semantic predicates are typically used to identify component
keywords in DRL files, such as declare, rule, exists, not, and
others.
Invalid Keyword
Example rule with an invalid keyword.- Must be a valid DRL keyword
Some text line is invalid because it does not begin with or is not a part of a DRL keyword construct, so the parser fails to validate the rest of the DRL file.
This error is similar to 102: mismatched input, but usually involves DRL keywords.
105: did not match anything
Indicates that the parser reached a sub-rule in the grammar that must match an alternative at least once, but the sub-rule did not match anything. The parser has entered a branch with no way out.