{"record":{"id":"01a29b79a95d7030","repo":"apache/skywalking","slug":"load-rule-failed","errorCode":null,"errorMessage":"Load rule {} failed","messagePattern":"Load rule (.+?) failed","errorType":"exception","errorClass":"UnexpectedException","httpStatus":null,"severity":"error","filePath":"oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/prometheus/rule/Rules.java","lineNumber":168,"sourceCode":"\n    private static Rule parseRule(final String rulesetDir, final String ruleName,\n                                  final String relPath, final byte[] bytes) {\n        // Decode once and bind from the String: RuleSourceLines re-composes the SAME text to read\n        // positional marks, which snakeyaml's bean binding discards.\n        final String text = new String(bytes, StandardCharsets.UTF_8);\n        try (Reader r = new StringReader(text)) {\n            Rule rule = new Yaml().loadAs(r, Rule.class);\n            if (rule == null) {\n                return null;\n            }\n            rule.setName(ruleName);\n            rule.setSourcePath(rulesetDir + \"/\"\n                + (relPath == null ? ruleName + \".yaml\" : relPath));\n            RuleSourceLines.assign(rule, text);\n            registerInlineLayers(ruleName, rule);\n            return rule;\n        } catch (IOException e) {\n            throw new UnexpectedException(\"Load rule \" + ruleName + \" failed\", e);\n        }\n    }\n\n    /**\n     * Funnel any inline {@code layerDefinitions:} entries through {@code Layer.register}.\n     * Conflict checks (reserved-range, name uniqueness, ordinal uniqueness, sealed-state) live\n     * in {@code Layer.register}; failures here surface with the offending rule name in\n     * the stack trace.\n     */\n    private static void registerInlineLayers(final String ruleName, final Rule rule) {\n        final List<LayerDefinition> defs = rule.getLayerDefinitions();\n        if (defs == null || defs.isEmpty()) {\n            return;\n        }\n        for (final LayerDefinition def : defs) {\n            try {\n                def.register();\n            } catch (RuntimeException e) {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/prometheus/rule/Rules.java#L150-L186","documentation":"UnexpectedException ('Load rule X failed') wrapping an IOException raised while a MAL rule's YAML text is being parsed by SnakeYAML (loadAs on a StringReader) inside parseRule. It fires at rule-load time for the named rule; the wrapped cause carries the underlying parse detail.","triggerScenarios":"SnakeYAML raising an IOException (in practice usually a wrapped YAML stream problem such as malformed content that surfaces during reader I/O) while parsing the rule body previously read from disk or from a merged/resolver source. The rule name in the message identifies which file failed.","commonSituations":"Malformed YAML in a custom rule (bad indentation, tabs, unclosed quotes) that manifests during load; rule files rewritten by config-management tooling that truncated them; rules coming from a runtime-rule resolver/DB whose stored bytes are not valid YAML.","solutions":["Open the named rule file and run it through a YAML linter — fix indentation, tabs, and quoting","If the rule comes from a dynamic/runtime source, re-validate the stored rule text before it is pushed","Compare against a known-good built-in rule file for structural keys (metric/exp/filter) — wrong key names can also derail parsing","Restart/reload rules after the fix; rule loading is fail-fast at startup"],"exampleFix":"# before\nmetricPrefix:\n  test\n  rule: bad_indent\n# after\nmetricPrefix: test\nrule: fixed","handlingStrategy":"validation","validationCode":"// CI gate: every rule file must parse as a Rule\nRule rule = new Yaml().loadAs(new String(Files.readAllBytes(p), StandardCharsets.UTF_8), Rule.class);\nassert rule != null && rule.getMetricPrefix() != null;","typeGuard":null,"tryCatchPattern":"catch (UnexpectedException e) { /* cause carries the YAML failure; fix the named file and reload */ }","preventionTips":["Lint all MAL rule YAMLs in CI (yamllint + SnakeYAML loadAs)","Compare structure against a known-good built-in rule","Never hand-edit rules on live nodes; change them in source control"],"tags":["mal","yaml","rule-config","meter-analyzer","startup"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}