apache/skywalking · error · IllegalArgumentException
MAL expression parsing failed: {} in expression: {}
Error message
MAL expression parsing failed: {} in expression: {} What it means
Generic MAL expression parse failure: MALScriptParser.parse ran the ANTLR parser over an expression (the rule's combined expPrefix+exp+expSuffix text in production), the error listener collected one or more syntax errors, and parsing aborted with IllegalArgumentException carrying the accumulated line:column messages. This is the top-level 'your MAL expression is not grammatically valid' error.
Source
Thrown at oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/MALScriptParser.java:235
final MALParser parser = new MALParser(tokens);
final List<String> errors = new ArrayList<>();
parser.removeErrorListeners();
parser.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(final Recognizer<?, ?> recognizer,
final Object offendingSymbol,
final int line,
final int charPositionInLine,
final String msg,
final RecognitionException e) {
errors.add(line + ":" + charPositionInLine + " " + msg);
}
});
final MALParser.ExpressionContext tree = parser.expression();
if (!errors.isEmpty()) {
throw new IllegalArgumentException(
"MAL expression parsing failed: " + String.join("; ", errors)
+ " in expression: " + expression);
}
return new MALExprVisitor().visit(tree.additiveExpression());
}
/**
* Parse a standalone filter closure expression into a {@link ClosureArgument}.
*
* @param filterExpression e.g. {@code "{ tags -> tags.job_name == 'mysql-monitoring' }"}
*/
public static ClosureArgument parseFilter(final String filterExpression) {
final MALLexer lexer = new MALLexer(CharStreams.fromString(filterExpression));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final MALParser parser = new MALParser(tokens);
final List<String> errors = new ArrayList<>();View on GitHub (pinned to 102af09b4a)
Solutions
- Use the line:column prefix in the message to locate the offending token in the expression printed after 'in expression:'
- Compare with a known-good rule in the same directory (e.g. otel-rules vm.yaml) for quoting and structure
- Rebuild the full combined expression via MetricConvert.formatExp logic (expPrefix + exp + expSuffix) when testing locally so you see exactly what the parser sees
- Wrap a unit test around DSL.parse / MALScriptParser.parse to iterate quickly without restarting OAP
Example fix
# before exp: cpu_usage.sum(['mode']) .avg(['host'] # after expr: cpu_usage.sum(['mode']).avg(['host'])
Defensive patterns
Strategy: try-catch
Validate before calling
try {
MALScriptParser.parse(expression);
} catch (IllegalArgumentException | IllegalStateException e) {
throw new AssertionError("MAL syntax error: " + e.getMessage());
} Try / catch
catch IllegalArgumentException/IllegalStateException from DSL.parse; log metricName + full expression + cause, and stop OAP so the bad rule cannot be half-loaded
Prevention
- Validate every rule file with the DSL test harness before merge
- Diff rule files against a known-good baseline after upgrades — grammar tightens between versions
- Read the line:column prefix — ANTLR messages locate the error precisely
When it happens
Trigger: Any grammar violation in the final expression string: unbalanced parentheses, wrong quoting (single vs double quotes outside closures), unsupported operators, missing commas in argument lists, malformed Layer enum references, or an expSuffix scope function typed incorrectly.
Common situations: Authoring or editing otel-rules/*.yaml, meter-analyzer-config, telegraf/zabbix rule files; version upgrades that tightened the grammar (v1 Groovy accepted expressions the v2 ANTLR grammar rejects); YAML escaping issues where '>' or quotes get mangled.
Related errors
- MAL expression parsing failed while injecting expPrefix: {}
- MAL filter expression parsing failed: {} in expression: {}
- Load meter analyzer configs failed
- {slot} value '{numText}' exceeds the supported range (must f
- Unclosed interpolation in: {s}
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/4101ee9d992a4a7e.
Report an issue: GitHub.