apache/skywalking · error · ParseCancellationException

line {}:{} {}

Error message

line {}:{} {}

What it means

ParseCancellationException produced by the ANTLR ParseErrorListener attached to the MQE parser. Any lexical or syntax error in an MQE (Metrics Query Expression) string aborts parsing immediately; the message embeds the offending line, column, and ANTLR's diagnosis. This is the user-facing syntax error for all MQE queries (GraphQL metricsExpression / queryType expressions).

Source

Thrown at oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/exception/ParseErrorListener.java:36

package org.apache.skywalking.mqe.rt.exception;

import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;

public class ParseErrorListener extends BaseErrorListener {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer,
                            Object offendingSymbol,
                            int line,
                            int charPositionInLine,
                            String msg,
                            RecognitionException e)
        throws ParseCancellationException {

        throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg);
    }
}

View on GitHub (pinned to 102af09b4a)

Solutions

  1. Use the reported line:column — it marks the exact offending token; fix the construct at that position
  2. Check the MQE grammar reference (docs/en/api/metrics-query-expression.md) for the function/duration/label syntax you used
  3. Simplify: paste the expression into the UI's MQE editor which surfaces the same error inline, and rebuild it piece by piece
  4. For JSON/GraphQL transport, verify quoting/escaping survived (inner double quotes must be escaped)

Example fix

# before
metricsExpression: sum(service_resp_time, pt5m)
# after
metricsExpression: aggregate_labels(service_resp_time.sum(dt5m), SUM)
Defensive patterns

Strategy: validation

Validate before calling

import org.apache.skywalking.mqe.rt.MQEVisitorBase; // or the parse entry your version exposes
// Dry-run parse before sending to the server:
try {
    org.apache.skywalking.oap.server.core.query.mqe.ExpressionResult r = MQEVisitorBase.parse(expression); // per API
} catch (ParseCancellationException e) { /* syntax error: fix line:col */ }

Try / catch

catch (ParseCancellationException e) {
    // e.getMessage() = "line L:C msg" — surface to the user at the exact position
    return badRequest("MQE syntax error: " + e.getMessage());
}

Prevention

When it happens

Trigger: An MQE string passed to the OAP GraphQL API that violates the MQE grammar: unbalanced parentheses, wrong function names, missing quotes around durations, invalid labels, stray characters. Example: 'service_sla/service_resp_time' typos or 'sum(' without close.

Common situations: Hand-writing MQE expressions in the UI custom dashboard or API calls; migrating PromQL habits into MQE (different function set); escaping issues when the expression is embedded in JSON/GraphQL payloads; UI version sending newer MQE syntax than the OAP supports.

Related errors


AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14). Data as JSON: /api/errors/600c580130bcf8a8. Report an issue: GitHub.