{"record":{"id":"ef7d6ab52791501b","repo":"apache/skywalking","slug":"failed-to-compile-mal-filter-expression","errorCode":null,"errorMessage":"Failed to compile MAL filter expression: {}","messagePattern":"Failed to compile MAL filter expression: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/FilterExpression.java","lineNumber":95,"sourceCode":"                if (filterNameHint != null) {\n                    perFile.setClassNameHint(filterNameHint);\n                }\n                perFile.setSourceRef(sourceRef);\n                this.malFilter = perFile.compileFilter(literal);\n            } else {\n                if (filterNameHint != null) {\n                    GENERATOR.setClassNameHint(filterNameHint);\n                }\n                GENERATOR.setSourceRef(sourceRef);\n                try {\n                    this.malFilter = GENERATOR.compileFilter(literal);\n                } finally {\n                    GENERATOR.setClassNameHint(null);\n                    GENERATOR.setYamlSource(null);\n                }\n            }\n        } catch (Exception e) {\n            throw new IllegalStateException(\n                \"Failed to compile MAL filter expression: \" + literal, e);\n        }\n    }\n\n    public Map<String, SampleFamily> filter(final Map<String, SampleFamily> sampleFamilies) {\n        try {\n            final Map<String, SampleFamily> result = new HashMap<>();\n            for (final Map.Entry<String, SampleFamily> entry : sampleFamilies.entrySet()) {\n                final SampleFamily afterFilter = entry.getValue().filter(malFilter::test);\n                if (!Objects.equals(afterFilter, SampleFamily.EMPTY)) {\n                    result.put(entry.getKey(), afterFilter);\n                }\n            }\n            return result;\n        } catch (Throwable t) {\n            log.error(\"failed to run \\\"{}\\\"\", literal, t);\n        }\n        return sampleFamilies;","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/FilterExpression.java#L77-L113","documentation":"IllegalStateException from the FilterExpression constructor when GENERATOR.compileFilter(literal) throws for the 'filter:' clause of a MAL rule. The filter sub-language (label matchers) is compiled ahead of data ingestion via a code generator; any lexer/parser/generator failure inside that compile is wrapped into this single exception that names the offending literal.","triggerScenarios":"A syntax error in the filter: field of a MAL rule YAML, e.g. unbalanced quotes, an unknown label-matcher operator, or a filter literal the v2 filter grammar does not accept. Raised at rule-load time (OAP startup or dynamic rule reload), before any samples are processed.","commonSituations":"Hand-editing filter expressions; copying a PromQL label matcher (e.g. '{job=\"x\"}' or '=~' regex forms) that the MAL filter grammar spells differently; version upgrades that changed the accepted filter syntax while the rule file was not updated.","solutions":["Read the wrapped cause (the IllegalStateException carries the original exception) — it pinpoints the exact filter syntax problem","Compare the filter literal against the MAL filter grammar/examples in docs/en/concepts-and-designs/meter-analysis-language.md and fix the syntax","Test the filter expression in a unit test that constructs FilterExpression directly so failures surface before OAP deploy","If the label name is wrong, verify the label actually exists on the ingested samples (typo'd label names compile but never match — while structural typos fail compile)"],"exampleFix":"# before\nfilter: 'src_service_name == \"gateway\" && status_code\" == 500'\n# after\nfilter: src_service_name == \"gateway\" && status_code == 500","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    FilterExpression fe = new FilterExpression(literal);\n} catch (IllegalStateException e) {\n    // e.getCause() carries the generator's precise syntax error\n    log.error(\"Bad MAL filter '{}': {}\", literal, e.getCause().getMessage());\n}","preventionTips":["Copy filter syntax from shipped rules rather than from PromQL","Cover every new filter clause with a unit test constructing FilterExpression","Read the cause exception, not just the wrapper message"],"tags":["mal","filter","dsl","meter-analyzer","rule-config"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}